Use Noda Time :)
This does not relieve you of the burden of thinking how you want to deal with it, but it allows you to specify how you want to deal with it. Essentially, you have been given a value that does not exist ... so you can choose an error, or perhaps start a transition, or the end of the transition, or some user behavior:
For example, a soft resolver will return the end of the transition:
using System;
using NodaTime;
class Test
{
static void Main()
{
var local = new LocalDateTime(2014, 3, 30, 2, 30, 0);
var zone = DateTimeZoneProviders.Tzdb["Europe/Paris"];
var zoned = local.InZoneLeniently(zone);
Console.WriteLine(zoned);
}
}
" " :
using System;
using NodaTime;
using NodaTime.TimeZones;
class Test
{
static void Main()
{
var local = new LocalDateTime(2014, 3, 30, 2, 30, 0);
var zone = DateTimeZoneProviders.Tzdb["Europe/Paris"];
var resolver = Resolvers.CreateMappingResolver(
ambiguousTimeResolver: Resolvers.ReturnEarlier,
skippedTimeResolver: Resolvers.ReturnEndOfIntervalBefore);
var zoned = local.InZone(zone, resolver);
Console.WriteLine(zoned);
}
}
( ).
, , . , . (, , /.)