public void Construct_FromLocal_ValidLaterOffset()
        {
            SingleTransitionDateTimeZone zone = new SingleTransitionDateTimeZone(Instant.FromUtc(2011, 6, 12, 22, 0), 4, 3);

            LocalDateTime local = new LocalDateTime(2011, 6, 13, 1, 30);
            ZonedDateTime zoned = new ZonedDateTime(local, zone, zone.LateInterval.WallOffset);

            // Map the local time to the later of the offsets in a way which is tested elsewhere.
            var resolver = Resolvers.CreateMappingResolver(Resolvers.ReturnLater, Resolvers.ThrowWhenSkipped);
            Assert.AreEqual(zoned, local.InZone(zone, resolver));
        }
        public void Construct_FromLocal_InvalidOffset()
        {
            SingleTransitionDateTimeZone zone = new SingleTransitionDateTimeZone(Instant.FromUtc(2011, 6, 12, 22, 0), 4, 3);

            // Attempt to ask for the later offset in the earlier interval
            LocalDateTime local = new LocalDateTime(2000, 1, 1, 0, 0, 0);
            Assert.Throws<ArgumentException>(() => new ZonedDateTime(local, zone, zone.LateInterval.WallOffset));
        }
        public void Equality()
        {
            // Goes back from 2am to 1am on June 13th
            SingleTransitionDateTimeZone zone = new SingleTransitionDateTimeZone(Instant.FromUtc(2011, 6, 12, 22, 0), 4, 3);
            var sample = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30)).First();
            var fromUtc = Instant.FromUtc(2011, 6, 12, 21, 30).InZone(zone);

            // Checks all the overloads etc: first check is that the zone matters
            TestHelper.TestEqualsStruct(sample, fromUtc, Instant.FromUtc(2011, 6, 12, 21, 30).InUtc());
            TestHelper.TestOperatorEquality(sample, fromUtc, Instant.FromUtc(2011, 6, 12, 21, 30).InUtc());

            // Now just use a simple inequality check for other aspects...

            // Different offset
            var later = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30)).Last();
            Assert.AreEqual(sample.LocalDateTime, later.LocalDateTime);
            Assert.AreNotEqual(sample.Offset, later.Offset);
            Assert.AreNotEqual(sample, later);

            // Different local time
            Assert.AreNotEqual(sample, zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 29)).First());

            // Different calendar
            var withOtherCalendar = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30, CalendarSystem.Gregorian)).First();
            Assert.AreNotEqual(sample, withOtherCalendar);
        }
        public void Construct_FromLocal_ValidUnambiguousOffset()
        {
            SingleTransitionDateTimeZone zone = new SingleTransitionDateTimeZone(Instant.FromUtc(2011, 6, 12, 22, 0), 4, 3);

            LocalDateTime local = new LocalDateTime(2000, 1, 2, 3, 4, 5);
            ZonedDateTime zoned = new ZonedDateTime(local, zone, zone.EarlyInterval.WallOffset);
            Assert.AreEqual(zoned, local.InZoneStrictly(zone));
        }
        public void WithZone()
        {
            Instant instant = Instant.FromUtc(2012, 2, 4, 12, 35);
            ZonedDateTime zoned = new ZonedDateTime(instant, SampleZone);
            Assert.AreEqual(new LocalDateTime(2012, 2, 4, 16, 35, 0), zoned.LocalDateTime);

            // Will be UTC-8 for our instant.
            DateTimeZone newZone = new SingleTransitionDateTimeZone(Instant.FromUtc(2000, 1, 1, 0, 0), -7, -8);
            ZonedDateTime converted = zoned.WithZone(newZone);
            Assert.AreEqual(new LocalDateTime(2012, 2, 4, 4, 35, 0), converted.LocalDateTime);
            Assert.AreEqual(converted.ToInstant(), instant);
        }
Beispiel #6
0
        /// <inheritdoc />
        protected override bool EqualsImpl(DateTimeZone zone)
        {
            SingleTransitionDateTimeZone otherZone = (SingleTransitionDateTimeZone)zone;

            return(Id == otherZone.Id && EarlyInterval.Equals(otherZone.EarlyInterval) && LateInterval.Equals(otherZone.LateInterval));
        }
 public void MapLocal_GapAroundAndInTailZoneTransition()
 {
     // Tail zone is -10 / +5, with the transition occurring just after
     // the transition *to* the tail zone from the precalculated zone.
     // A local time of one hour after the transition from the precalculated zone (which is -5)
     // will therefore be in the gap.
     var tailZone = new SingleTransitionDateTimeZone(ThirdInterval.End + Duration.FromHours(1), -10, +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(new ZoneInterval("Single-Early", ThirdInterval.End, tailZone.Transition, Offset.FromHours(-10), Offset.Zero),
                     mapping.LateInterval);
     Assert.AreEqual(0, mapping.Count);
 }
 public void MapLocal_AmbiguousButTooEarlyInTailZoneTransition()
 {
     // Tail zone is +10 / +8, with the transition occurring just after
     // the transition *to* the tail zone from the precalculated zone.
     // A local instant of one hour before after the transition from the precalculated zone (which is -5)
     // will therefore be ambiguous, but the resulting instants from the ambiguity occur
     // before our transition into the tail zone, so are ignored.
     var tailZone = new SingleTransitionDateTimeZone(ThirdInterval.End + Duration.FromHours(1), 10, 8);
     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 TrickyCase()
 {
     // 1am occurs unambiguously in the early zone.
     var zone = new SingleTransitionDateTimeZone(Transition, Offset.FromHours(3), Offset.FromHours(5));
     var mapping = zone.MapLocal(new LocalDateTime(2000, 1, 1, 1, 0));
     CheckMapping(mapping, zone.EarlyInterval, zone.EarlyInterval, 1);
 }