1

I'm trying to calculate the correct DST offset for the point in time when the UK switches to BST which should be at 1am on 2021-03-28.

I have a fiddle here: https://dotnetfiddle.net/8gdVIG

For completeness, this is the code I'm running:

var timeZoneInfo = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tzi => tzi.Id.Equals("Europe/London", StringComparison.InvariantCultureIgnoreCase));

Console.WriteLine($"No. of adjustment rules: {timeZoneInfo.GetAdjustmentRules().Count()}");
var firstRule = timeZoneInfo.GetAdjustmentRules().FirstOrDefault(r => new DateTime(2021,03,28,1,59,0) >= r.DateStart && new DateTime(2021,03,28,1,59,0) <= r.DateEnd);
Console.WriteLine($"            Day: {firstRule.DaylightTransitionStart.Day}");
Console.WriteLine($"      DayOfWeek: {firstRule.DaylightTransitionStart.DayOfWeek}");
Console.WriteLine($"IsFixedDateRule: {firstRule.DaylightTransitionStart.IsFixedDateRule}");
Console.WriteLine($"          Month: {firstRule.DaylightTransitionStart.Month}");
Console.WriteLine($"      TimeOfDay: {firstRule.DaylightTransitionStart.TimeOfDay}");
Console.WriteLine($"           Week: {firstRule.DaylightTransitionStart.Week}");
Console.WriteLine($"Offset at 01:59 on 2021-03-28: {timeZoneInfo.GetUtcOffset(new DateTime(2021,03,28,1,59,0)).Hours}");

The results of which are:

No. of adjustment rules: 244
            Day: 28
      DayOfWeek: Sunday
IsFixedDateRule: True
          Month: 3
      TimeOfDay: 01/01/0001 01:00:00
           Week: 1
Offset at 01:59 on 2021-03-28: 0

And yet the offset at 2am is the 1 hour I expect at 1am.

Console.WriteLine($"Offset at 02:00 on 2021-03-28: {timeZoneInfo.GetUtcOffset(new DateTime(2021,03,28,2,0,0)).Hours}");

Output:

Offset at 02:00 on 2021-03-28: 1

Why is the UTC offset not 1 hour at 1am? Do I really need Noda Time just to get the correct local DST offset?

0

1 Answer 1

3

2021-03-28T01:00:00 doesn't exist in the UK time zone - nor does 01:59:00. We skip at 1am straight to 2am. So the first value printed in your code is with an invalid date/time value.

The documentation is (surprisingly) clear about this:

If dateTime is invalid, this method returns a TimeSpan object that reflects the difference between UTC and the time zone's standard time.

And as the standard time in the UK is the same as UTC, it's correct to print 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.