New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unix.mktime fails or is incorrect on Windows #6215
Comments
Comment author: @protz Are you positive that you're running the exact same executable? |
Comment author: daweil Yes. Can you reproduce the issue on one of your machine ? |
Comment author: @protz Yes, I can confirm. This is strange indeed. |
Comment author: @protz The Cygwin shell defines the TZ environment variable while the Windows shell does not. This is what's causing the difference in behavior. To reproduce the error in a Cygwin shell, just run unset TZ then launch your test program. |
Comment author: @protz The underlying problem has something to do with DST (Dayling Saving Time). I strongly suspect this is not a bug, in the sense that:
protzenk@sauternes:/tmp $ TZ=Europe/Paris ./a.out more than one hour is 1.000000 second one hour is 0.000000 second Fatal error: exception Unix.Unix_error(32, "mktime", "") protzenk@sauternes:/tmp $ TZ=USA/New_York ./a.out more than one hour is 3601.000000 second one hour is 3600.000000 second less than one hour is 3599.000000 second and 2) The conclusion is, the date returned by gmtime(3599.), when interpreted with DST on or off, I have no idea which, represents one second before the epoch, thus a date that's not representable, hence the ERANGE message. The documentation explicitly says that the tm argument of mktime is interpreted in the local time zone http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html |
Comment author: @protz I'm marking this as no change required, since I strongly suspect nothing's wrong with OCaml. |
Comment author: daweil OK. As the behavior is surprising, could you just add something in the documentation of the gmtime function ? |
Original bug ID: 6215
Reporter: daweil
Assigned to: @protz
Status: closed (set by @xavierleroy on 2015-12-11T18:24:18Z)
Resolution: not a bug
Priority: normal
Severity: major
Platform: mingw
OS: Windows
Version: 4.01.0
Category: otherlibs
Bug description
Function Unix.mktime fails in windows for time <= 3599 seconds
and is incorrect for time > 3600. seconds.
note that it works fine in a cygwin shell, but fails outside (in a DOS shell)
Steps to reproduce
compile the attached ml file :
ocamlbuild bugMkTime.native -tag use_unix -no-links
then
_build/bugMkTime.native
In a "Dos" or "MsysGit" shell, the output is
more than one hour is 1.000000 second
one hour is 0.000000 second
Fatal error: exception Unix.Unix_error(32, "mktime", "")
while in a cygwin shell (with the same executable file), the output is correct :
more than one hour is 3601.000000 second
one hour is 3600.000000 second
less than one hour is 3599.000000 second
File attachments
The text was updated successfully, but these errors were encountered: