Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005063OCamlotherlibspublic2010-05-28 18:472016-12-07 16:59
Assigned To 
PlatformOSOS Version
Product Version3.11.2 
Target VersionFixed in Version 
Summary0005063: Unix module does not offer access to tzname
DescriptionThe "Time Functions" in the Unix module provide comprehensive coverage of the time-related operations available in Libc. There is one conspicuous absence, however: the tzname variable, which provides access to the DST-adjusted abbreviated name of the current timezone. Presently, accessing this value from an Ocaml program requires writing a small C function.
Additional InformationThe function 'sprint_timestamp' listed below returns a string with the given timestamp pretty-printed in a complete form, ie, including also the abbreviated timezone name adjusted for daylight-savings. It must be written in C, since the Unix module offers no access to the tzname variable.

CAMLprim value sprint_timestamp (value v_time)

        CAMLparam1 (v_time);
        CAMLlocal1 (v_res);

        time_t time = Double_val (v_time);
        struct tm* lt = localtime (&time);
        char res [40];
        snprintf (res, sizeof (res), "%04d-%02d-%02d %02d:%02d:%02d (%s)",
                (lt->tm_year) + 1900, (lt->tm_mon) + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, tzname [lt->tm_isdst]);
        v_res = caml_copy_string (res);

        CAMLreturn (v_res);
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2010-05-28 18:47 dario New Issue
2011-06-01 23:01 doligez Status new => acknowledged
2013-09-05 11:51 doligez Tag Attached: patch
2016-12-07 16:59 shinwell Category OCaml general => OCaml otherlibs
2017-02-23 16:42 doligez Category OCaml otherlibs => otherlibs

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker