GetUtcOffset returns the wrong off set for certain years / dates

334 views Asked by At
 var currentServerOffset = TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(1972, 03, 19, 02, 00, 00);

using the above returns the wrong offset, but when you pass through 26th March it is corrected.

it seems that this is off for a whole week, in my tests this has been in 1972 and 1973 ref: https://greenwichmeantime.com/info/calendars/bst-dates/

I am thinking it could be something to do with GetDaylightChanges being wrong in these years ref: https://learn.microsoft.com/en-us/dotnet/api/system.timezone.getdaylightchanges?view=netframework-4.8#remarks

as when i call this passing in 1972 or 1973 the start is off by 7 days.

How do i get around this?

1

There are 1 answers

1
howsec On BEST ANSWER

We couldn't get GetUtcOffset to work with historic dates. Instead we used Noda Time which should be as easy as:

var dt = Instant.FromUtc(1972, 03, 19, 02, 00, 00);
DateTimeZone zone = DateTimeZoneProviders.Tzdb["Europe/London"];
Offset offset = zone.GetUtcOffset(dt);