Question

I have some NodaTime code that is looking at zone intervals:

var zone = DateTimeZoneProviders.Tzdb["America/Phoenix"];
var interval = zone.GetZoneInterval(SystemClock.Instance.Now);
Console.WriteLine(interval.End);
Console.WriteLine(interval.IsoLocalEnd);

interval.End outputs EOT, which is expected since this zone does not use daylight savings time. But I cannot output the interval.IsoLocalEnd value. It throws an exception:

System.ArgumentOutOfRangeException was unhandled
  HResult=-2146233086
  Message=Value should be in range [-27255-31195]
Parameter name: year
Actual value was 31197.
  Source=NodaTime
  ParamName=year
  StackTrace:
       at NodaTime.Utility.Preconditions.CheckArgumentRange(String paramName, Int32 value, Int32 minInclusive, Int32 maxInclusive)
       at NodaTime.Calendars.BasicCalendarSystem.GetYearTicks(Int32 year)
       at NodaTime.Calendars.GregorianCalendarSystem.GetYearTicks(Int32 year)
       at NodaTime.Calendars.BasicGJCalendarSystem.GetMonthOfYear(LocalInstant localInstant, Int32 year)
       at NodaTime.Calendars.BasicCalendarSystem.GetMonthOfYear(LocalInstant localInstant)
       at NodaTime.Fields.BasicMonthOfYearDateTimeField.GetValue(LocalInstant localInstant)
       at NodaTime.LocalDateTime.get_Month()
       at NodaTime.Text.LocalDateTimePatternParser.<.cctor>b__8(LocalDateTime value)
       at NodaTime.Text.Patterns.DatePatternHelper.<>c__DisplayClassd`2.<>c__DisplayClass10.<CreateMonthOfYearHandler>b__c(TResult value, StringBuilder sb)
       at NodaTime.NodaAction`2.Invoke(TArg1 arg1, TArg2 arg2)
       at NodaTime.Text.Patterns.SteppedPatternBuilder`2.SteppedPattern.Format(TResult value)
       at NodaTime.Text.Patterns.PatternBclSupport`1.Format(T value, String patternText, NodaFormatInfo formatInfo)
       at NodaTime.LocalDateTime.ToString(String patternText, IFormatProvider formatProvider)
       at System.IO.TextWriter.WriteLine(Object value)
       at System.IO.TextWriter.SyncTextWriter.WriteLine(Object value)

Is this a bug? Or is this expected behavior and I should check interval.End == Instant.MaxValue before trying to use the interval.IsoLocalEnd value?

I am using NodaTime 1.1.0.

Was it helpful?

Solution

In general, Noda Time has some issues with converting instants to local dates at points close to (or at) the end of time. See e.g. issue 197 and issue 113. This appears to be another occurrence of the same kind of problem.

I'd suggest filing a bug. One suggestion, though: check whether you see the same results with Noda Time 1.0: the fix for issue 197 (in 1.1.0) could conceivably have caused this as a regression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top