Skip to content
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

Util.Date.make_from_gmt is incorrect? #2

Open
camlspotter opened this issue Mar 5, 2013 · 0 comments
Open

Util.Date.make_from_gmt is incorrect? #2

camlspotter opened this issue Mar 5, 2013 · 0 comments

Comments

@camlspotter
Copy link
Collaborator

The code looks like:

let make_from_gmt year mon day h m s =
  let diff =  fst (mktime (gmtime 0.)) in
  make year mon day h m s -. diff

where make calls Unix.mktime. I think it is wrong. Since Japan Standard Time has no summertime since 1952 and its timezone is fixed, the code above works for the posix Unix epochs if your timezone is set to JST. But it does not world wide.

diff is intended to be the diff seconds between UTC and the local time, but it is not universal in general. diff is just the epoch diff between 1970/01/01T00:00:00Z (UTC) and 1970/01/01 00:00:00 of the local time.

The diff seconds between UTC and the local time of diffrent year-mon-day h:m:s can be diffrent.

let f t = fst (Unix.mktime (Unix.gmtime t)) -. t

If you are in Singapore,

f 0.0 = -27000.0

but

f (Unix.time ()) = -28800.0

You have 30min difference. This is due to the historical timezone change of SGT near 1981.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant