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

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

             reply	other threads:[~2010-03-06  9:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-06  9:53 Luca de Alfaro [this message]
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

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=28fa90931003060153y5c4d1590j97fcc0267ee2dc1e@mail.gmail.com \
    --to=luca@dealfaro.org \
    --cc=caml-list@inria.fr \
    /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).