toit icon indicating copy to clipboard operation
toit copied to clipboard

Time on Windows doesn't deal with dates before 1970

Open floitsch opened this issue 2 years ago • 0 comments

We are using gmtime_s and localtime_s on Windows.

However, both of these functions don't accept negative seconds (since epoch), and thus don't work for dates before 1970.

Currently neither the Windows, nor the Posix versions check that the system calls actually succeed. (Both should).

The nicest is probably to try the system call, and then fall back to an equivalent range if the system call fails. See V8 for how to map to an equivalent range: https://github.com/v8/v8/blob/21ab8287a61ef260a2ae7a38f42426fa6f35c39c/src/date/date.h#L113

Test is currently marked as failing on Windows (permalink to current revision): https://github.com/toitlang/toit/blob/8d5aea4826d4cdf59ca1a16acc0bf3b018660c93/tests/fail.cmake#L29

floitsch avatar Jan 23 '23 10:01 floitsch