public void NextTwice_FirstYear() { var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition? actual = recurrence.Next(NodaConstants.UnixEpoch, Offset.Zero, Offset.Zero); actual = recurrence.Next(actual.Value.Instant, Offset.Zero, Offset.Zero); Transition? expected = new Transition(Instant.FromUtc(1972, 1, 1, 0, 0), Offset.Zero); Assert.AreEqual(expected, actual); }
public void NextTwice_FirstYear() { var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition?actual = recurrence.Next(NodaConstants.UnixEpoch, Offset.Zero, Offset.Zero); actual = recurrence.Next(actual.Value.Instant, Offset.Zero, Offset.Zero); Transition?expected = new Transition(new Instant(NodaConstants.UnixEpoch.Ticks + (2 * TicksPerStandardYear)), Offset.Zero, Offset.Zero); Assert.AreEqual(expected, actual); }
public void Next_FirstYear() { var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, Offset.Zero); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition? actual = recurrence.Next(Instant.UnixEpoch, Offset.Zero, Offset.Zero); Transition? expected = new Transition(new Instant(Instant.UnixEpoch.Ticks + (1 * TicksPerStandardYear)), Offset.Zero, Offset.Zero); Assert.AreEqual(expected, actual); }
public void Next_BeforeFirstYear() { var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, Offset.Zero); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition? actual = recurrence.Next(Instant.MinValue, Offset.Zero, Offset.Zero); Transition? expected = new Transition(Instant.UnixEpoch, Offset.Zero, Offset.Zero); Assert.AreEqual(expected, actual); }
public void Next_BeyondLastYear_null() { var afterRecurrenceEnd = Instant.FromUtc(1980, 1, 1, 0, 0); var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition? actual = recurrence.Next(afterRecurrenceEnd, Offset.Zero, Offset.Zero); Transition? expected = null; Assert.AreEqual(expected, actual); }
public void Next_BeforeFirstYear() { var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition?actual = recurrence.Next(Instant.MinValue, Offset.Zero, Offset.Zero); Transition?expected = new Transition(NodaConstants.UnixEpoch, Offset.Zero, Offset.Zero); Assert.AreEqual(expected, actual); }
public void December31st2400_AskAtNanoBeforeLastTransition() { // The transition occurs after the end of the maximum // Each year, the transition is at the midnight at the *end* of December 31st... var yearOffset = new ZoneYearOffset(TransitionMode.Utc, 12, 31, 0, true, LocalTime.Midnight, true); // ... and the recurrence is valid for the whole of time var recurrence = new ZoneRecurrence("awkward", Offset.FromHours(1), yearOffset, 1, 5000); // We can find the final transition var finalTransition = Instant.FromUtc(5001, 1, 1, 0, 0); var next = recurrence.Next(finalTransition - Duration.Epsilon, Offset.Zero, Offset.Zero); Transition?expected = new Transition(finalTransition, Offset.FromHours(1)); Assert.AreEqual(expected, next); // But we correctly reject anything after that Assert.IsNull(recurrence.Next(finalTransition, Offset.Zero, Offset.Zero)); }
public void Next_ExcludesGivenInstant() { var january10thMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 10, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("x", Offset.Zero, january10thMidnight, 2000, 3000); var transition = Instant.FromUtc(2500, 1, 10, 0, 0); var next = recurrence.Next(transition, Offset.Zero, Offset.Zero); Assert.AreEqual(2501, next.Value.Instant.InUtc().Year); }
public void Next_BeyondLastYear_null() { var afterRecurrenceEnd = Instant.FromUtc(1980, 1, 1, 0, 0); var januaryFirstMidnight = new ZoneYearOffset(TransitionMode.Utc, 1, 1, 0, true, LocalTime.Midnight); var recurrence = new ZoneRecurrence("bob", Offset.Zero, januaryFirstMidnight, 1970, 1972); Transition?actual = recurrence.Next(afterRecurrenceEnd, Offset.Zero, Offset.Zero); Transition?expected = null; Assert.AreEqual(expected, actual); }
public void December31st2400_MaxYear_UtcTransition() { // Each year, the transition is at the midnight at the *end* of December 31st... var yearOffset = new ZoneYearOffset(TransitionMode.Utc, 12, 31, 0, true, LocalTime.Midnight, true); // ... and the recurrence is valid for the whole of time var recurrence = new ZoneRecurrence("awkward", Offset.FromHours(1), yearOffset, GregorianYearMonthDayCalculator.MinGregorianYear, GregorianYearMonthDayCalculator.MaxGregorianYear); var next = recurrence.Next(Instant.FromUtc(9999, 6, 1, 0, 0), Offset.Zero, Offset.Zero); Assert.AreEqual(Instant.AfterMaxValue, next.Value.Instant); }
private ZoneTransition GetNext(Instant nextInstant) { // Find next matching rule. ZoneRecurrence nextRule = null; Instant nextTicks = Instant.MaxValue; for (int i = 0; i < rules.Count; i++) { ZoneRecurrence rule = rules[i]; Transition? nextTransition = rule.Next(nextInstant, ruleSet.StandardOffset, savings); Instant? next = nextTransition == null ? (Instant?)null : nextTransition.Value.Instant; if (!next.HasValue || next.Value <= nextInstant) { rules.RemoveAt(i); i--; continue; } // Even if next is same as previous next, choose the rule in order for more // recently added rules to override. if (next.Value <= nextTicks) { // Found a better match. nextRule = rule; nextTicks = next.Value; } } if (nextRule == null) { return(null); } // Stop precalculating if year reaches some arbitrary limit. We can cheat in the // conversion because it is an approximation anyway. if (calendar.GetYear(nextTicks.Plus(Offset.Zero)) >= YearLimit) { return(null); } // Check if upper limit reached or passed. if (ruleSet.upperYear < Int32.MaxValue) { Instant upperTicks = ruleSet.upperYearOffset.MakeInstant(ruleSet.upperYear, ruleSet.StandardOffset, savings); if (nextTicks >= upperTicks) { // At or after upper limit. return(null); } } return(new ZoneTransition(nextTicks, nextRule.Name, ruleSet.StandardOffset, nextRule.Savings)); }
public void December31st2400_AskAtNanoBeforeLastTransition() { // The transition occurs after the end of the maximum // Each year, the transition is at the midnight at the *end* of December 31st... var yearOffset = new ZoneYearOffset(TransitionMode.Utc, 12, 31, 0, true, LocalTime.Midnight, true); // ... and the recurrence is valid for the whole of time var recurrence = new ZoneRecurrence("awkward", Offset.FromHours(1), yearOffset, 1, 5000); // We can find the final transition var finalTransition = Instant.FromUtc(5001, 1, 1, 0, 0); var next = recurrence.Next(finalTransition - Duration.Epsilon, Offset.Zero, Offset.Zero); Transition? expected = new Transition(finalTransition, Offset.FromHours(1)); Assert.AreEqual(expected, next); // But we correctly reject anything after that Assert.IsNull(recurrence.Next(finalTransition, Offset.Zero, Offset.Zero)); }