/// <inheritdoc />
        public DateTimeZone GetZoneOrNull([NotNull] string id)
        {
            Preconditions.CheckNotNull(id, nameof(id));
            DateTimeZone fixedZone = FixedDateTimeZone.GetFixedZoneOrNull(id);

            if (fixedZone != null)
            {
                return(fixedZone);
            }
            lock (accessLock)
            {
                DateTimeZone zone;
                if (!timeZoneMap.TryGetValue(id, out zone))
                {
                    return(null);
                }
                if (zone == null)
                {
                    zone = source.ForId(id);
                    if (zone == null)
                    {
                        throw new InvalidDateTimeZoneSourceException("Time zone " + id + " is supported by source " + VersionId + " but not returned");
                    }
                    timeZoneMap[id] = zone;
                }
                return(zone);
            }
        }
 public void ZoneIntervalNameDefaultsToZoneId()
 {
     var zone = new FixedDateTimeZone("id", Offset.FromHours(5));
     var interval = zone.GetZoneInterval(NodaConstants.UnixEpoch);
     Assert.AreEqual("id", interval.Name);
     Assert.AreEqual("id", zone.Name);
 }
 public void ExplicitNameAppearsInZoneInterval()
 {
     var zone = new FixedDateTimeZone("id", Offset.FromHours(5), "name");
     var interval = zone.GetZoneInterval(NodaConstants.UnixEpoch);
     Assert.AreEqual("id", zone.Id); // Check we don't get this wrong...
     Assert.AreEqual("name", interval.Name);
     Assert.AreEqual("name", zone.Name);
 }
 public void MinMaxOffsetsWithOtherTailZone()
 {
     var tailZone = new FixedDateTimeZone("TestFixed", Offset.FromHours(8));
     var testZone = new PrecalculatedDateTimeZone("Test",
         new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone);
     Assert.AreEqual(Offset.FromHours(-5), testZone.MinOffset);
     Assert.AreEqual(Offset.FromHours(8), testZone.MaxOffset);
 }
 public void FromDateTimeOffset()
 {
     DateTimeOffset dateTimeOffset = new DateTimeOffset(2011, 3, 5, 1, 0, 0, TimeSpan.FromHours(3));
     DateTimeZone fixedZone = new FixedDateTimeZone(Offset.FromHours(3));
     ZonedDateTime expected = fixedZone.AtStrictly(new LocalDateTime(2011, 3, 5, 1, 0, 0));
     ZonedDateTime actual = ZonedDateTime.FromDateTimeOffset(dateTimeOffset);
     Assert.AreEqual(expected, actual);
 }
        public void Roundtrip()
        {
            var ioHelper = DtzIoHelper.CreateNoStringPool();
            var oldZone = new FixedDateTimeZone("id", Offset.FromHours(4), "name");
            oldZone.Write(ioHelper.Writer);
            var newZone = (FixedDateTimeZone) FixedDateTimeZone.Read(ioHelper.Reader, "id");

            Assert.AreEqual(oldZone.Id, newZone.Id);
            Assert.AreEqual(oldZone.Offset, newZone.Offset);
            Assert.AreEqual(oldZone.Name, newZone.Name);
        }
Exemple #7
0
 /// <inheritdoc />
 public DateTimeZone?GetZoneOrNull(string id)
 {
     Preconditions.CheckNotNull(id, nameof(id));
     return(GetZoneFromSourceOrNull(id) ?? FixedDateTimeZone.GetFixedZoneOrNull(id));
 }
        protected override bool EqualsImpl(DateTimeZone other)
        {
            FixedDateTimeZone otherZone = (FixedDateTimeZone)other;

            return(offset == otherZone.offset && Id == other.Id);
        }
 public void MapLocal_GapAroundTailZoneTransition()
 {
     // Tail zone is fixed at +5. A local time at the transition
     // from the precalculated zone (which is -5) will therefore give an instant from
     // the tail zone which occurs before the precalculated-to-tail transition,
     // and can therefore be ignored, resulting in an overall gap.
     var tailZone = new FixedDateTimeZone(Offset.FromHours(5));
     var gapZone = new PrecalculatedDateTimeZone("Test", 
         new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone);
     var mapping = gapZone.MapLocal(ThirdInterval.IsoLocalEnd);
     Assert.AreEqual(ThirdInterval, mapping.EarlyInterval);
     Assert.AreEqual(new ZoneInterval("UTC+05", ThirdInterval.End, Instant.AfterMaxValue, Offset.FromHours(5), Offset.Zero),
                     mapping.LateInterval);
     Assert.AreEqual(0, mapping.Count);
 }
 public void MapLocal_SingleIntervalAroundTailZoneTransition()
 {
     // Tail zone is fixed at +5. A local instant of one hour before the transition
     // from the precalculated zone (which is -5) will therefore give an instant from
     // the tail zone which occurs before the precalculated-to-tail transition,
     // and can therefore be ignored, resulting in an overall unambiguous time.
     var tailZone = new FixedDateTimeZone(Offset.FromHours(5));
     var gapZone = new PrecalculatedDateTimeZone("Test",
         new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone);
     var mapping = gapZone.MapLocal(ThirdInterval.IsoLocalEnd.PlusHours(-1));
     Assert.AreEqual(ThirdInterval, mapping.EarlyInterval);
     Assert.AreEqual(ThirdInterval, mapping.LateInterval);
     Assert.AreEqual(1, mapping.Count);
 }
 public void GetZoneIntervals_GapAroundTailZoneTransition()
 {
     // Tail zone is fixed at +5. A local instant of one hour after the transition
     // from the precalculated zone (which is -5) will therefore give an instant from
     // the tail zone which occurs before the precalculated-to-tail transition,
     // and can therefore be ignored, resulting in an overall gap.
     var tailZone = new FixedDateTimeZone(Offset.FromHours(5));
     var gapZone = new PrecalculatedDateTimeZone("Test", 
         new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone);
     var actual = gapZone.GetZoneIntervals(ThirdInterval.LocalEnd);
     var expected = ZoneIntervalPair.NoMatch;
     Assert.AreEqual(expected, actual);
 }
 public void GetZoneIntervals_SingleIntervalAroundTailZoneTransition()
 {
     // Tail zone is fixed at +5. A local instant of one hour before the transition
     // from the precalculated zone (which is -5) will therefore give an instant from
     // the tail zone which occurs before the precalculated-to-tail transition,
     // and can therefore be ignored, resulting in an overall unambiguous time.
     var tailZone = new FixedDateTimeZone(Offset.FromHours(5));
     var gapZone = new PrecalculatedDateTimeZone("Test",
         new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone);
     var pair = gapZone.GetZoneIntervals(ThirdInterval.LocalEnd - Duration.FromHours(1));
     Assert.AreEqual(ThirdInterval, pair.EarlyInterval);
     Assert.IsNull(pair.LateInterval);
 }