From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 32DBCBC57 for ; Sat, 6 Mar 2010 10:53:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnQBAAe1kUtKfVwakGdsb2JhbACbQwgVAQEBAQkJDAcTAx+1EIR4BIMX X-IronPort-AV: E=Sophos;i="4.49,593,1262559600"; d="scan'208";a="46018548" Received: from qw-out-2122.google.com ([74.125.92.26]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Mar 2010 10:53:56 +0100 Received: by qw-out-2122.google.com with SMTP id 8so944033qwh.33 for ; Sat, 06 Mar 2010 01:53:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.107.29 with SMTP id z29mr1081561qco.42.1267869235788; Sat, 06 Mar 2010 01:53:55 -0800 (PST) X-Originating-IP: [63.203.46.196] Date: Sat, 6 Mar 2010 01:53:55 -0800 Message-ID: <28fa90931003060153y5c4d1590j97fcc0267ee2dc1e@mail.gmail.com> Subject: Ocaml can't convert a GMT time into a float! From: Luca de Alfaro To: Inria Ocaml Mailing List Content-Type: multipart/alternative; boundary=0023544714ac6bbe8404811ecf84 X-Spam: no; 0.00; ocaml:01 ocaml:01 mktime:01 isdst:01 yday:01 isdst:01 mktime:01 yday:01 daylight:98 3600:98 daylight:98 3600:98 unix:01 unix:01 differs:01 --0023544714ac6bbe8404811ecf84 Content-Type: text/plain; charset=ISO-8859-1 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}) --0023544714ac6bbe8404811ecf84 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I need to convert a time, expressed in yyyy/mm/dd hh:mm:ss form, into a flo= ating point.
The conversion has to be done in GMT, but the real point i= s, the conversion must NOT change due to daylight savings time.

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

No proble= m, 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!=A0 Look at the two conversions below.=A0 The tmrec = differs by one hour.
However, the two floating point numbers returned a= re 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 expres= sed 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 su= ch library function in Ocaml.
I will have to write it from basic princip= les.
Anybody has a better suggestion?

Many thanks,

Luca

# let tmrec =3D {tm_sec =3D 38; tm_min =3D 57; tm_hour =3D 3; t= m_mday =3D 11; tm_mon =3D 2; tm_year =3D 107; tm_wday =3D 0; tm_yday =3D 0;= tm_isdst =3D false};;
# Unix.mktime tmrec;;
- : float * Unix.tm =3D<= br>(1173610658.,
=A0{tm_sec =3D 38; tm_min =3D 57; tm_hour =3D 3; tm_mday =3D 11; tm_mon =3D= 2;=A0 tm_year =3D 107; tm_wday =3D 0; tm_yday =3D 69; tm_isdst =3D true})<= br>
# let tmrec =3D {tm_sec =3D 38; tm_min =3D 57; tm_hour =3D 2; tm_mda= y =3D 11; tm_mon =3D 2; tm_year =3D 107; tm_wday =3D 0; tm_yday =3D 0; tm_i= sdst =3D false};;
# Unix.mktime tmrec;;
- : float * Unix.tm =3D
(1173610658.,
=A0{tm= _sec =3D 38; tm_min =3D 57; tm_hour =3D 3; tm_mday =3D 11; tm_mon =3D 2;=A0 tm_year =3D 107; tm_wday =3D 0; tm_yday =3D 69; tm_isdst =3D true})
--0023544714ac6bbe8404811ecf84--