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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 60437BC57 for ; Sat, 6 Mar 2010 14:19:56 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvoAANbkkUtKfVI2mGdsb2JhbACPNowNCBUBAQEBAQgJDAcTIqVlCoFXhGUtiEkBAQMFhHMEgxeINw X-IronPort-AV: E=Sophos;i="4.49,594,1262559600"; d="scan'208";a="54139589" Received: from mail-ww0-f54.google.com ([74.125.82.54]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Mar 2010 14:19:56 +0100 Received: by wwb17 with SMTP id 17so2376337wwb.27 for ; Sat, 06 Mar 2010 05:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=J2I+zIWgGSugBhCXBSEwjQ4RyYAPrSo0Fx8n1Jtogn0=; b=dxs9j3kIgeoOOhOSRrwcYdGAitgpeemJFjFAS00smjg9+m/p39aYMylWNmvaowCbM8 E9P1545BSz4TZgtbGw2OXvliD0mMgkSV0Kvr5OGQHI4C9qaJiAYIm5eAP3QshK9cWwmE DMyo4Nz1Bswlxv11zrgMVh2BUnmGaF932QJ/c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=jLAA2+vwac+4FkoNsjW4P3APzfgd7s+BmZwqpEB53q/9lQy2jNea5kx54u+aZvUjyq tTx+PQpx27pVHeoS8hOMtlHrreb2f+T+sUaEr/clMaIIfidql63E4G+qDfCGEm8djRgh +a79lQhgS3mVNbdsBMt4VOT7Hd3lrKZD4J4qc= MIME-Version: 1.0 Received: by 10.216.86.9 with SMTP id v9mr1027605wee.148.1267881595931; Sat, 06 Mar 2010 05:19:55 -0800 (PST) Reply-To: yminsky@gmail.com In-Reply-To: <28fa90931003060153y5c4d1590j97fcc0267ee2dc1e@mail.gmail.com> References: <28fa90931003060153y5c4d1590j97fcc0267ee2dc1e@mail.gmail.com> Date: Sat, 6 Mar 2010 08:19:55 -0500 Message-ID: <891bd3391003060519m4cb97821u8f8b6ee165870f95@mail.gmail.com> Subject: Re: [Caml-list] Ocaml can't convert a GMT time into a float! From: Yaron Minsky To: Luca de Alfaro Cc: Inria Ocaml Mailing List Content-Type: multipart/alternative; boundary=0016e6da7ae3248bd6048121b0be X-Spam: no; 0.00; ocaml:01 yaron:01 minsky:01 yminsky:01 ocaml:01 mktime:01 isdst:01 yday:01 isdst:01 mktime:01 yday:01 beginner's:01 bug:01 beginner's:01 bug:01 --0016e6da7ae3248bd6048121b0be Content-Type: text/plain; charset=ISO-8859-1 The TZ module in Core could also be helpful here. y On Sat, Mar 6, 2010 at 4:53 AM, Luca de Alfaro 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 > > --0016e6da7ae3248bd6048121b0be Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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, 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})

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--0016e6da7ae3248bd6048121b0be--