Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ocaml can't convert a GMT time into a float!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yaron Minsky <yminsky@g...>
Subject: Re: [Caml-list] Ocaml can't convert a GMT time into a float!
The TZ module in Core could also be helpful here.

y

On Sat, Mar 6, 2010 at 4:53 AM, Luca de Alfaro <luca@dealfaro.org> wrote:

> 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})
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>