caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@gmail.com>
To: Luca de Alfaro <luca@dealfaro.org>
Cc: Inria Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Ocaml can't convert a GMT time into a float!
Date: Sat, 6 Mar 2010 08:19:55 -0500	[thread overview]
Message-ID: <891bd3391003060519m4cb97821u8f8b6ee165870f95@mail.gmail.com> (raw)
In-Reply-To: <28fa90931003060153y5c4d1590j97fcc0267ee2dc1e@mail.gmail.com>

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

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
>
>

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

  parent reply	other threads:[~2010-03-06 13:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-06  9:53 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 [this message]
2010-03-07  3:27 ` Dave Benjamin
2010-03-07 18:05   ` Luca de Alfaro
2010-03-07 18:12     ` Luca de Alfaro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=891bd3391003060519m4cb97821u8f8b6ee165870f95@mail.gmail.com \
    --to=yminsky@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=luca@dealfaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).