public void ZoneWithAmbiguity_JustBeforeAmbiguity() { var actual = ZoneWithAmbiguity.GetZoneIntervalPair(TransitionMinus5 - Duration.Epsilon); var expected = ZoneIntervalPair.Unambiguous(IntervalBeforeAmbiguity); Assert.AreEqual(expected, actual); }
public void ZoneWithAmbiguity_JustAfterTransition() { var actual = ZoneWithAmbiguity.GetZoneIntervalPair(TransitionPlus10 + Duration.Epsilon); var expected = ZoneIntervalPair.Unambiguous(IntervalAfterAmbiguity); Assert.AreEqual(expected, actual); }
public void ZoneWithAmbiguity_EndOfTime() { var actual = ZoneWithAmbiguity.GetZoneIntervalPair(LocalInstant.MaxValue); var expected = ZoneIntervalPair.Unambiguous(IntervalAfterAmbiguity); Assert.AreEqual(expected, actual); }
public void ZoneWithAmbiguity_WellAfterTransition() { var actual = ZoneWithAmbiguity.GetZoneIntervalPair(YearAfterTransition); var expected = ZoneIntervalPair.Unambiguous(IntervalAfterAmbiguity); Assert.AreEqual(expected, actual); }
public void ZoneWithAmbiguity_StartOfTime() { var actual = ZoneWithAmbiguity.GetZoneIntervalPair(LocalInstant.MinValue); var expected = ZoneIntervalPair.Unambiguous(IntervalBeforeAmbiguity); Assert.AreEqual(expected, actual); }
public void ZoneWithGap_FirstTickAfterTransition() { var actual = ZoneWithGap.GetZoneIntervalPair(TransitionPlus10); var expected = ZoneIntervalPair.Unambiguous(IntervalAfterGap); Assert.AreEqual(expected, actual); }
public void ZoneWithGap_WellBeforeTransition() { var actual = ZoneWithGap.GetZoneIntervalPair(YearBeforeTransition); var expected = ZoneIntervalPair.Unambiguous(IntervalBeforeGap); Assert.AreEqual(expected, actual); }
public void TrickyCase() { // 1am occurs unambiguously in the early zone. var zone = new SingleTransitionDateTimeZone(Transition, Offset.FromHours(3), Offset.FromHours(5)); var actual = zone.GetZoneIntervalPair(new LocalInstant(2000, 1, 1, 1, 0)); var expected = ZoneIntervalPair.Unambiguous(zone.EarlyInterval); Assert.AreEqual(expected, actual); }
/// <summary> /// Finds all zone intervals for the given local instant. Usually there's one (i.e. only a single /// instant is mapped to the given local instant within the time zone) but during DST transitions /// there can be either 0 (the given local instant doesn't exist, e.g. local time skipped from 1am to /// 2am, but you gave us 1.30am) or 2 (the given local instant is ambiguous, e.g. local time skipped /// from 2am to 1am, but you gave us 1.30am). /// </summary> /// <remarks> /// This method is implemented in terms of GetZoneInterval(Instant) within DateTimeZone, /// and should work for any zone. However, internal derived classes may override this method /// for optimization purposes, e.g. if the zone interval is always ambiguous with /// a fixed value. /// </remarks> /// <param name="localInstant">The local instant to find matching zone intervals for</param> /// <returns>The struct containing up to two ZoneInterval references.</returns> internal virtual ZoneIntervalPair GetZoneIntervalPair(LocalInstant localInstant) { Instant firstGuess = new Instant(localInstant.Ticks); ZoneInterval interval = GetZoneInterval(firstGuess); // Most of the time we'll go into here... the local instant and the instant // are close enough that we've found the right instant. if (interval.Contains(localInstant)) { ZoneInterval earlier = GetEarlierMatchingInterval(interval, localInstant); if (earlier != null) { return(ZoneIntervalPair.Ambiguous(earlier, interval)); } ZoneInterval later = GetLaterMatchingInterval(interval, localInstant); if (later != null) { return(ZoneIntervalPair.Ambiguous(interval, later)); } return(ZoneIntervalPair.Unambiguous(interval)); } else { // Our first guess was wrong. Either we need to change interval by one (either direction) // or we're in a gap. ZoneInterval earlier = GetEarlierMatchingInterval(interval, localInstant); if (earlier != null) { return(ZoneIntervalPair.Unambiguous(earlier)); } ZoneInterval later = GetLaterMatchingInterval(interval, localInstant); if (later != null) { return(ZoneIntervalPair.Unambiguous(later)); } return(ZoneIntervalPair.NoMatch); } }
public void MatchingIntervals_SingleInterval() { ZoneIntervalPair pair = ZoneIntervalPair.Unambiguous(new ZoneInterval("Foo", new Instant(0), new Instant(10), Offset.Zero, Offset.Zero)); Assert.AreEqual(1, pair.MatchingIntervals); }