Pure OCaml implementation of Clock.gmtime on xen #2
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.
The code may not be as efficient as the C @talex5 was refering to. But at least I understand the algorithms behind the proposal modulo the well sourced calendrical formulae (see the comments in the patch).
If I understand correctly the english from the specification
gmtime
is only defined on non-negative timestamps (or strictly positive, unclear). We still do implement it on negative values by using the proleptic gregorian calendar which is whatgmtime
seems to be doing on both macosx and linux according to my cross-checks.Testing. The PR has a function in
lib_test/xen_gmtime.ml
that was used to test the implementation for differences against theUnix.gmtime
of both linux and macosx.One test is randomized tests with time values that span 200 years around the epoch, this includes negative values. The other is a sequential test that tests every second since a particular point in time (in the patch, 0. the epoch) until you get bored.
Here are the results:
0.
) was tested until 2430 AD and no difference was found.gmtime
. So rather I did a sequential test starting from the minimal signed (-2_147_483_648.
) 32 bits timestamp at ~1901 AD and ran the sequence until I witnessed the 2038 bug, i.e. past2^31 - 1
:No difference was found in between.
I hope this can improve our confidence in the correctness of the function, at least w.r.t. the implementation of other unixes. I'll still be glad if someone can review this thoroughly.