We have a line of code:
DateTime.Now.AddMinutes(-1);
Which ran at 2:00 on the morning of the 29th of March 2015 in the UK. The returned value was 1:59, however because of the transition to summer time 1:59 didn't actually happen and caused exceptions further down the line.
In my opinion this is a bug in .NET however in lieu of getting a fix to the framework how can we validate that this is a valid DateTime before the following lines throw exceptions?
I'm really looking for an extension method along the lines of.
if(!theDate.IsValidInTimezone(TimeZoneInfo.Local))
{
// the time is not valid
}
TimeZoneInfo.IsInvalidTime method could help you here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With