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); }
public void GetZoneIntervals_GapAroundAndInTailZoneTransition() { // Tail zone is -10 / +5, with the transition occurring just after // the transition *to* the tail zone from the precalculated zone. // A local instant of one hour after the transition from the precalculated zone (which is -5) // will therefore be in the gap. No zone interval matches, so the result is // an empty pair. var tailZone = new SingleTransitionDateTimeZone(ThirdInterval.End + Duration.FromHours(1), -10, +5); var gapZone = new PrecalculatedDateTimeZone("Test", new[] { FirstInterval, SecondInterval, ThirdInterval }, tailZone); var pair = gapZone.GetZoneIntervalPair(ThirdInterval.LocalEnd + Duration.FromHours(1)); Assert.IsNull(pair.EarlyInterval); Assert.IsNull(pair.LateInterval); }
public void InZoneStrictly_InvalidInterval() { // Arrange var instant = Fixture.Create <Instant>(); var timeZone = new SingleTransitionDateTimeZone(instant, 5, 4); var start = instant - Duration.FromMinutes(15); var end = instant + Duration.FromMinutes(15); var interval = new Interval(start, end); // Act Action act = () => interval.InZoneStrictly(timeZone); // Assert act.Should().ThrowExactly <InvalidLocalDateTimeInterval>(); }
public void GetZoneIntervals_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 pair = gapZone.GetZoneIntervalPair(ThirdInterval.LocalEnd - Duration.FromHours(1)); Assert.AreEqual(ThirdInterval, pair.EarlyInterval); Assert.IsNull(pair.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); }