caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Ocaml can't convert a GMT time into a float!
@ 2010-03-06  9:53 Luca de Alfaro
  2010-03-06 11:09 ` [Caml-list] " blue storm
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Luca de Alfaro @ 2010-03-06  9:53 UTC (permalink / raw)
  To: Inria Ocaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1696 bytes --]

I need to convert a time, expressed in yyyy/mm/dd hh:mm:ss form, into a
floating point.
The conversion has to be done in GMT, but the real point is, the conversion
must NOT change due to daylight savings time.

Ocaml seems to have only one conversion function, however: Unix.mktime,
which takes a time, and makes a float in the local time zone.

No problem, I thought: I will simply add 3600 if the conversion result tells
me that dst is active (and then convert for the difference between GMT and
winter time).
NO! This does not work!  Look at the two conversions below.  The tmrec
differs by one hour.
However, the two floating point numbers returned are identical, and tm_isdst
is set to true in both cases!

This means that I have no way of using the standard libraries to convert a
time expressed in yyyy/mm/ss hh:mm:ss to a float!

This is a basic operation, and it is a big let down that there is no such
library function in Ocaml.
I will have to write it from basic principles.
Anybody has a better suggestion?

Many thanks,

Luca

# let tmrec = {tm_sec = 38; tm_min = 57; tm_hour = 3; tm_mday = 11; tm_mon =
2; tm_year = 107; tm_wday = 0; tm_yday = 0; tm_isdst = false};;
# Unix.mktime tmrec;;
- : float * Unix.tm =
(1173610658.,
 {tm_sec = 38; tm_min = 57; tm_hour = 3; tm_mday = 11; tm_mon = 2;  tm_year
= 107; tm_wday = 0; tm_yday = 69; tm_isdst = true})

# let tmrec = {tm_sec = 38; tm_min = 57; tm_hour = 2; tm_mday = 11; tm_mon =
2; tm_year = 107; tm_wday = 0; tm_yday = 0; tm_isdst = false};;
# Unix.mktime tmrec;;
- : float * Unix.tm =
(1173610658.,
 {tm_sec = 38; tm_min = 57; tm_hour = 3; tm_mday = 11; tm_mon = 2;
  tm_year = 107; tm_wday = 0; tm_yday = 69; tm_isdst = true})

[-- Attachment #2: Type: text/html, Size: 1814 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-03-07 18:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-06  9:53 Ocaml can't convert a GMT time into a float! Luca de Alfaro
2010-03-06 11:09 ` [Caml-list] " blue storm
2010-03-06 12:47   ` Erik de Castro Lopo
2010-03-06 13:19 ` Yaron Minsky
2010-03-07  3:27 ` Dave Benjamin
2010-03-07 18:05   ` Luca de Alfaro
2010-03-07 18:12     ` Luca de Alfaro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).