/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer to write to.</param> internal void Write([NotNull] IDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, nameof(writer)); // We used to create a pool of strings just for this zone. This was more efficient // for some zones, as it meant that each string would be written out with just a single // byte after the pooling. Optimizing the string pool globally instead allows for // roughly the same efficiency, and simpler code here. writer.WriteCount(periods.Length); Instant?previous = null; foreach (var period in periods) { writer.WriteZoneIntervalTransition(previous, (Instant)(previous = period.RawStart)); writer.WriteString(period.Name); writer.WriteOffset(period.WallOffset); writer.WriteOffset(period.Savings); } writer.WriteZoneIntervalTransition(previous, tailZoneStart); // We could just check whether we've got to the end of the stream, but this // feels slightly safer. writer.WriteByte((byte)(tailZone == null ? 0 : 1)); if (tailZone != null) { // This is the only kind of zone we support in the new format. Enforce that... var tailDstZone = (DaylightSavingsDateTimeZone)tailZone; tailDstZone.Write(writer); } }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteSignedCount(latitudeSeconds); writer.WriteSignedCount(longitudeSeconds); writer.WriteString(ZoneId); writer.WriteString(Comment); }
private static void WriteZone(DateTimeZone zone, IDateTimeZoneWriter writer) { writer.WriteString(zone.Id); // For cached zones, simply uncache first. var cachedZone = zone as CachedDateTimeZone; if (cachedZone != null) { zone = cachedZone.TimeZone; } var fixedZone = zone as FixedDateTimeZone; if (fixedZone != null) { writer.WriteByte((byte)DateTimeZoneWriter.DateTimeZoneType.Fixed); fixedZone.Write(writer); } else { var precalculatedZone = zone as PrecalculatedDateTimeZone; if (precalculatedZone != null) { writer.WriteByte((byte)DateTimeZoneWriter.DateTimeZoneType.Precalculated); precalculatedZone.Write(writer); } else { throw new ArgumentException("Unserializable DateTimeZone type " + zone.GetType()); } } }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteSignedCount(latitudeSeconds); writer.WriteSignedCount(longitudeSeconds); writer.WriteString(countryName); writer.WriteString(countryCode); writer.WriteString(zoneId); writer.WriteString(comment); }
/// <summary> /// Writes this object to the given <see cref="DateTimeZoneWriter"/>. /// </summary> /// <param name="writer">Where to send the output.</param> internal void Write(IDateTimeZoneWriter writer) { writer.WriteString(Name); writer.WriteOffset(Savings); YearOffset.Write(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 this mapping to a writer. /// </summary> /// <param name="writer"></param> internal void Write(IDateTimeZoneWriter writer) { writer.WriteString(WindowsId); writer.WriteString(Territory); writer.WriteCount(TzdbIds.Count); foreach (string id in TzdbIds) { writer.WriteString(id); } }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteString(Version); writer.WriteString(TzdbVersion); writer.WriteString(WindowsVersion); writer.WriteCount(MapZones.Count); foreach (var mapZone in MapZones) { mapZone.Write(writer); } }
/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer to write to.</param> internal void Write(IDateTimeZoneWriter writer) { // We don't need everything a recurrence can supply: we know that both recurrences should be // infinite, and that only the DST recurrence should have savings. Preconditions.CheckNotNull(writer, nameof(writer)); writer.WriteOffset(standardOffset); writer.WriteString(standardRecurrence.Name); standardRecurrence.YearOffset.Write(writer); writer.WriteString(dstRecurrence.Name); dstRecurrence.YearOffset.Write(writer); writer.WriteOffset(dstRecurrence.Savings); }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteSignedCount(latitudeSeconds); writer.WriteSignedCount(longitudeSeconds); writer.WriteCount(Countries.Count); // TODO (2.0): Consider writing out the ISO-3166 file as a separate field, // so we can reuse objects. We don't actually waste very much this way, mind you, due to the string pool... foreach (var country in Countries) { writer.WriteString(country.Name); writer.WriteString(country.Code); } writer.WriteString(ZoneId); writer.WriteString(Comment); }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteSignedCount(latitudeSeconds); writer.WriteSignedCount(longitudeSeconds); writer.WriteCount(Countries.Count); // We considered writing out the ISO-3166 file as a separate field, // so we can reuse objects, but we don't actually waste very much space this way, // due to the string pool... and the increased code complexity isn't worth it. foreach (var country in Countries) { writer.WriteString(country.Name); writer.WriteString(country.Code); } writer.WriteString(ZoneId); writer.WriteString(Comment); }
/// <summary> /// Writes this object to the given <see cref="IDateTimeZoneWriter"/>. /// </summary> /// <param name="writer">Where to send the output.</param> internal void Write(IDateTimeZoneWriter writer) { // Flags contains four pieces of information in a single byte: // 0MMDDDAP: // - MM is the mode (0-2) // - DDD is the day of week (0-7) // - A is the AdvanceDayOfWeek // - P is the "addDay" (24:00) flag int flags = ((int)Mode << 5) | (dayOfWeek << 2) | (AdvanceDayOfWeek ? 2 : 0) | (addDay ? 1 : 0); writer.WriteByte((byte)flags); writer.WriteCount(monthOfYear); writer.WriteSignedCount(dayOfMonth); // The time of day is written as a number of milliseconds historical reasons. writer.WriteMilliseconds((int)(TimeOfDay.TickOfDay / NodaConstants.TicksPerMillisecond)); }
/// <summary> /// Writes this object to the given <see cref="IDateTimeZoneWriter"/>. /// </summary> /// <param name="writer">Where to send the output.</param> internal void Write(IDateTimeZoneWriter writer) { // Flags contains four pieces of information in a single byte: // 0MMDDDAP: // - MM is the mode (0-2) // - DDD is the day of week (0-7) // - A is the AdvanceDayOfWeek // - P is the "addDay" (24:00) flag int flags = ((int)mode << 5) | (dayOfWeek << 2) | (advance ? 2 : 0) | (addDay ? 1 : 0); writer.WriteByte((byte)flags); writer.WriteCount(monthOfYear); writer.WriteSignedCount(dayOfMonth); // The time of day is written as an offset for historical reasons. writer.WriteOffset(Offset.FromTicks(timeOfDay.LocalDateTime.LocalInstant.Ticks)); }
/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer.</param> internal void Write([NotNull] IDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, nameof(writer)); writer.WriteOffset(Offset); writer.WriteString(Name); }
private static void WriteZone(DateTimeZone zone, IDateTimeZoneWriter writer) { writer.WriteString(zone.Id); // For cached zones, simply uncache first. var cachedZone = zone as CachedDateTimeZone; if (cachedZone != null) { zone = cachedZone.TimeZone; } var fixedZone = zone as FixedDateTimeZone; if (fixedZone != null) { writer.WriteByte((byte) DateTimeZoneWriter.DateTimeZoneType.Fixed); fixedZone.Write(writer); } else { var precalculatedZone = zone as PrecalculatedDateTimeZone; if (precalculatedZone != null) { writer.WriteByte((byte) DateTimeZoneWriter.DateTimeZoneType.Precalculated); precalculatedZone.Write(writer); } else { throw new ArgumentException("Unserializable DateTimeZone type " + zone.GetType()); } } }
/// <summary> /// Writes the time zone to the specified writer. /// </summary> /// <param name="writer">The writer.</param> internal void Write(IDateTimeZoneWriter writer) { Preconditions.CheckNotNull(writer, "writer"); writer.WriteOffset(offset); }
internal FieldData(TzdbStreamFieldId fieldId, IList <string> stringPool) { this.fieldId = fieldId; this.stream = new MemoryStream(); this.writer = new DateTimeZoneWriter(stream, stringPool); }
internal void Write(IDateTimeZoneWriter writer) { writer.WriteSignedCount(latitudeSeconds); writer.WriteSignedCount(longitudeSeconds); writer.WriteString(CountryName); writer.WriteString(CountryCode); writer.WriteString(ZoneId); writer.WriteString(Comment); }