Repository navigation
Correct date conversions - #75
Merged
Merged
Conversation
We need to be very careful with date conversions because C# does not use the IANA timezone database to determine offsets from UTC / daylight savings time. However, V8 does use the IANA timezone database which lead to discrepancies in the date conversion. Example: Germany did not observe daylight savings time from 1950-1979 and therefore observed UTC+1 throughout the whole year. However, C# thinks Germany did observe daylight savings time and assumes incorrectly that Germany observed UTC+2 during the summer time. V8 new Date(1978, 5, 15) // "Thu Jun 15 1978 00:00:00 GMT+0100 (Mitteleuropäische Normalzeit)" C# If we get the ticks since 1970-01-01 from V8 to construct a UTC DateTime object we get "1978-06-14 23:00:00" which is correct. A subsequent call to .ToLocalTime() on that date object yields "1978-06-15 01:00:00" which is wrong; it should be "1978-06-15 00:00:00"! The same problem exists in the other direction. We therefore construct date objects directly from the date components we get from V8 and vice versa.
oliverbock
approved these changes
Mar 4, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unfortunately we discovered another nasty edge case regarding the date conversion 👀😞
@oliverbock, @Ablu: Can you please review this very carefully? I only added new tests and did not touch the old ones. AFAIK there is no API to set the current time zone; it is determined by the operation system. So I could not write tests for a specific time zone. Rather I executed the date tests manually after setting my time zone locally. They were green in all the samples I took.
Problem
We need to be very careful with date conversions because C# does not use the IANA timezone database to determine offsets from UTC / daylight savings time. However, V8 does use the IANA timezone database which leads to discrepancies in the date conversion.
Example
Germany did not observe daylight savings time from 1950-1979 and therefore observed UTC+1 throughout the whole year. However, C# thinks Germany did observe daylight savings time and assumes incorrectly that Germany observed UTC+2 during the summer time.
V8
C#
If we get the ticks since
1970-01-01from V8 to construct a UTCDateTimeobject we get"1978-06-14 23:00:00"which is correct. A subsequent call to.ToLocalTime()on that date object yields"1978-06-15 01:00:00"which is wrong; it should be"1978-06-15 00:00:00"!The same problem exists in the other direction.
We therefore construct date objects directly from the date components we get from V8 and vice versa. I used this approach because I did not want to pull in a dependency on e.g. NodaTime. The C++ API currently doesn't offer a correct implementation either.