-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
For context our application is hosted in the Europe/Amsterdam timezone and we use dates dating back in the 1900's. Throughout the years different daylight saving rules are applied to this timezone. This is where there we found a weird problem where a wrong timezone offset is used for summer days in years where there should be no daylight time savings yet. Here is the code on how to see the issue:
//System timezone Europe/Amsterdam (GMT+1 without daylight saving, GMT+2 with daylight saving)
// Date before daylight saving time was introduced
var beforeDaylightSaving = DateTime.Parse("1958-07-03T23:00:00.000Z");
var beforeDaylightSavingISOString = beforeDaylightSaving.ToString("s");
//Results in GMT +2: 1958-07-04T01:00:00
//Expected GMT +1: 1958-07-04T00:00:00
//NOT OK
// Date in daylight saving time
var daylightSaving = DateTime.Parse("2000-07-03T22:00:00.000Z");
var daylightSavingISOString = daylightSaving.ToString("s");
//Results in GMT +2: 2000-07-04T00:00:00
//Expected GMT +2: 2000-07-04T00:00:00
//OK
// Date outside of daylight saving time
var noDaylightSaving = DateTime.Parse("2000-11-03T23:00:00.000Z");
var noDaylightSavingISOString = noDaylightSaving.ToString("s");
//Results in GMT +1: 2000-11-04T00:00:00
//Expected GMT +1: 2000-11-04T00:00:00
//OK
In the above example there are 3 scenario's
- A date in summer months in a year where DTS was not applicable (Before 1977)
- A date in summer months in a year where DTS was applicable
- A date in winter months in a year where DTS was applicable
Out of these 3 scenario's the first scenario is done incorrectly, there are 2 hours added in the DateTime after parsing the ISO string. This should be just 1 hour as in the year 1958 Daylight saving time did not exist in the Netherlands.
These same 3 scenario's can be tested in Javascript by just doing new Date(isoString) in the browser console, this results in the correct behavior. I would expect the same in .NET here.
Configuration
- Tested this on .NET Core 3.1 and the old .NET Framework 4.7
- Windows 10 x64
- Important: Timezone Europe/Amsterdam