private IanaRelease(TzdbDateTimeZoneSource source) { this.source = source; var locations = source.ZoneLocations?.ToDictionary(location => location.ZoneId) ?? new Dictionary <string, TzdbZoneLocation>(); Zones = source .GetIds() .Where(x => source.CanonicalIdMap[x] == x) .OrderBy(x => x) .Select(id => new Zone(source, locations, id)) .ToList(); }
public void ResourceZoneEquivalence() { var streamSource = TzdbDateTimeZoneSource.Default; #pragma warning disable 0618 var resourceSource = new TzdbDateTimeZoneSource("NodaTime.Test.TestData.Tzdb", Assembly.GetExecutingAssembly()); #pragma warning restore 0618 Assert.AreEqual(streamSource.VersionId, resourceSource.VersionId); CollectionAssert.AreEquivalent(streamSource.GetIds(), resourceSource.GetIds()); var interval = new Interval(Instant.FromUtc(1850, 1, 1, 0, 0), Instant.FromUtc(2050, 1, 1, 0, 0)); var comparer = ZoneEqualityComparer.ForInterval(interval).WithOptions(ZoneEqualityComparer.Options.StrictestMatch); foreach (var id in streamSource.GetIds()) { Assert.IsTrue(comparer.Equals(streamSource.ForId(id), resourceSource.ForId(id)), "Zone {0} is equal under stream and resource formats", id); } }
public void Dump(TextWriter writer) { var zones = source.GetIds() .Select(source.ForId) .OrderBy(zone => zone.Id, StringComparer.Ordinal) .ToList(); if (options.ZoneId != null) { if (options.HashOnly) { // TODO: Maybe allow this after all, and include the zone ID in the headers? throw new UserErrorException("Cannot use hash option with a single zone ID"); } var zone = zones.FirstOrDefault(z => z.Id == options.ZoneId); if (zone is null) { throw new UserErrorException($"Unknown zone ID: {options.ZoneId}"); } DumpZone(zone, writer); } else { var bodyWriter = new StringWriter(); foreach (var zone in zones) { DumpZone(zone, bodyWriter); } var text = bodyWriter.ToString(); if (options.HashOnly) { writer.Write(ComputeHash(text) + "\n"); } else { WriteHeaders(text, writer); writer.Write(text); } } }