/// <summary> /// Writes the time zone to the specified legacy writer. /// </summary> /// <param name="writer">The writer to write to.</param> internal void WriteLegacy(LegacyDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, "writer"); writer.WriteOffset(standardOffset); dstRecurrence.WriteLegacy(writer); standardRecurrence.WriteLegacy(writer); }
/// <summary> /// Writes dictionary of string to string to a resource with the given name. /// </summary> /// <param name="name">The resource name.</param> /// <param name="dictionary">The <see cref="IDictionary{TKey,TValue}" /> to write.</param> private void WriteDictionary(string name, IDictionary <string, string> dictionary) { using (var stream = new MemoryStream()) { var writer = new LegacyDateTimeZoneWriter(stream, null); writer.WriteDictionary(dictionary); resourceWriter.AddResource(name, stream.ToArray()); } }
internal void WriteLegacy(LegacyDateTimeZoneWriter writer) { writer.WriteString(Name); writer.WriteOffset(Savings); YearOffset.WriteLegacy(writer); // We'll never have time zones with recurrences between the beginning of time and 0AD, // so we can treat anything negative as 0, and go to the beginning of time when reading. writer.WriteCount(Math.Max(fromYear, 0)); writer.WriteCount(toYear); }
/// <summary> /// Writes a time zone to a resource with the time zone ID, normalized. /// </summary> /// <param name="timeZone">The <see cref="DateTimeZone" /> to write.</param> private void WriteTimeZone(DateTimeZone timeZone) { string normalizedId = TzdbResourceData.NormalizeAsResourceName(timeZone.Id); using (var stream = new MemoryStream()) { var writer = new LegacyDateTimeZoneWriter(stream, null); writer.WriteTimeZone(timeZone); resourceWriter.AddResource(normalizedId, stream.ToArray()); } }
/// <summary> /// Writes this object to the given <see cref="LegacyDateTimeZoneWriter"/>. /// </summary> /// <param name="writer">Where to send the output.</param> internal void WriteLegacy(LegacyDateTimeZoneWriter writer) { writer.WriteCount((int)mode); // Day of month can range from -31 to 31, so we add a suitable amount to force it to be positive. // The other values cannot, but we offset them for legacy reasons. writer.WriteCount(monthOfYear + 12); writer.WriteCount(dayOfMonth + 31); writer.WriteCount(dayOfWeek + 7); writer.WriteBoolean(advance); // The time of day is written as an offset for historical reasons. writer.WriteOffset(Offset.FromTicks(timeOfDay.LocalDateTime.LocalInstant.Ticks)); writer.WriteBoolean(addDay); }
/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer to write to.</param> internal void WriteLegacy(LegacyDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, "writer"); // Keep a pool of strings; we don't want to write the same strings out time and time again. List <string> stringPool = new List <string>(); foreach (var period in periods) { string name = period.Name; if (!stringPool.Contains(name)) { stringPool.Add(name); } } writer.WriteCount(stringPool.Count); foreach (string name in stringPool) { writer.WriteString(name); } writer.WriteCount(periods.Length); Instant?previous = null; foreach (var period in periods) { writer.WriteZoneIntervalTransition(previous, (Instant)(previous = period.Start)); int nameIndex = stringPool.IndexOf(period.Name); if (stringPool.Count < 256) { writer.WriteByte((byte)nameIndex); } else { writer.WriteInt32(nameIndex); } writer.WriteOffset(period.WallOffset); writer.WriteOffset(period.Savings); } writer.WriteZoneIntervalTransition(previous, tailZoneStart); writer.WriteTimeZone(tailZone); }
/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer to write to.</param> internal void WriteLegacy(LegacyDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, "writer"); writer.WriteTimeZone(timeZone); }