NodaTime does not seem to have an equivalent of TimeZoneInfo.IsInvalidTime.
Well, rather than just asking that one question - and then having to ask follow-on ones - you use DateTimeZone.MapLocal
. That gives you everything you could know about a local to UTC mapping: whether it's unambiguous, ambiguous, or invalid.
Alternatively, use ResolveLocal
but with your own custom SkippedTimeResolver
delegate.
For example, making this change makes your code work for me:
private static readonly ZoneLocalMappingResolver CustomResolver =
Resolvers.CreateMappingResolver(Resolvers.ReturnLater, AddGap);
// SkippedTimeResolver which adds the length of the gap to the
// local date and time.
private static ZonedDateTime AddGap(LocalDateTime localDateTime,
DateTimeZone zone,
ZoneInterval intervalBefore,
ZoneInterval intervalAfter)
{
long afterMillis = intervalAfter.WallOffset.Milliseconds;
long beforeMillis = intervalBefore.WallOffset.Milliseconds;
Period gap = Period.FromMilliseconds(afterMillis - beforeMillis);
return zone.AtStrictly(localDateTime + gap);
}
(There are other equivalent ways of doing it, of course.)
I'd personally suggest trying to avoid converting to and from DateTime
unless you really have to - I would do as much as possible in Noda Time.