caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Time stamp module floating around?
@ 2007-01-21  2:42 Denis Bueno
  2007-01-21  3:48 ` [Caml-list] " Chris King
  2007-01-21  8:43 ` skaller
  0 siblings, 2 replies; 5+ messages in thread
From: Denis Bueno @ 2007-01-21  2:42 UTC (permalink / raw)
  To: OCaml Mailing List

I'm looking for simple bit of code that will print human-readable
timestamps. Something suitable for a log file.

I'm generating some logs for unit tests, and I would like the preamble
to a particular unit test's log file to read: '/foo/bar test ran 20
Jan 2007 at 21:41" or something similar.

I could write this module, but I figure there's *got* to be something
out there better than I would make in the time I have.

Thanks in advance.

-Denis


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Time stamp module floating around?
  2007-01-21  2:42 Time stamp module floating around? Denis Bueno
@ 2007-01-21  3:48 ` Chris King
  2007-01-21  8:43 ` skaller
  1 sibling, 0 replies; 5+ messages in thread
From: Chris King @ 2007-01-21  3:48 UTC (permalink / raw)
  To: Denis Bueno; +Cc: OCaml Mailing List

On 1/20/07, Denis Bueno <dbueno@gmail.com> wrote:
> I'm looking for simple bit of code that will print human-readable
> timestamps. Something suitable for a log file.

I noticed Calendar [1] on the Hump a while ago... it looks pretty
useful.  The API includes a pretty printer.

[1] http://www.lri.fr/~signoles/prog.en.html

- Chris


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Time stamp module floating around?
  2007-01-21  2:42 Time stamp module floating around? Denis Bueno
  2007-01-21  3:48 ` [Caml-list] " Chris King
@ 2007-01-21  8:43 ` skaller
  2007-01-21  9:24   ` Nicolas George
  1 sibling, 1 reply; 5+ messages in thread
From: skaller @ 2007-01-21  8:43 UTC (permalink / raw)
  To: Denis Bueno; +Cc: OCaml Mailing List

On Sat, 2007-01-20 at 21:42 -0500, Denis Bueno wrote:
> I'm looking for simple bit of code that will print human-readable
> timestamps. Something suitable for a log file.

(*
Scrap used in Felix for lines like: 

//Timestamp: 2007/1/12 18:36:37 UTC
//Timestamp: 2007/1/13 5:36:37 (local)
*)


let tim() = 
  let now = (Unix.times()).Unix.tms_utime in
  let elapsed = now -. !last_time in
  last_time := now;
  elapsed
;;

let format_time tm = 
  si (tm.Unix.tm_year + 1900) ^ "/" ^
  si (tm.Unix.tm_mon + 1) ^ "/" ^
  si tm.Unix.tm_mday ^ " " ^
  si tm.Unix.tm_hour ^ ":" ^
  si tm.Unix.tm_min ^ ":" ^
  si tm.Unix.tm_sec 
;;
try
  (* Time initialisation *)
  let compile_start = Unix.time () in
  let compile_start_gm = Unix.gmtime compile_start in
  let compile_start_local = Unix.localtime compile_start in
  let compile_start_gm_string = format_time compile_start_gm ^ " UTC" in
  let compile_start_local_string = format_time compile_start_local ^
" (local)" in


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Time stamp module floating around?
  2007-01-21  8:43 ` skaller
@ 2007-01-21  9:24   ` Nicolas George
  2007-01-21  9:53     ` Robert Roessler
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas George @ 2007-01-21  9:24 UTC (permalink / raw)
  To: Caml mailing list

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

Le duodi 2 pluviôse, an CCXV, skaller a écrit :
> //Timestamp: 2007/1/12 18:36:37 UTC

I would strongly advise you tu use fixed-length fields with leading zeros:
the big advantage of using the year-month-day order, instead of
month-day-year or day-month-year, is that the lexical order of the string is
the same as the chronological order of the date. Using variable-length
fields breaks this. Furthermore, it makes it harder to parse the timestamp.

On the other hand, it is important not to forget "UTC".

While I am at it, I believe that yyyy-mm-dd is a more common format as
yyyy/mm/dd.

> //Timestamp: 2007/1/13 5:36:37 (local)

It is a shame that whoever designed the tm structure in the first place
forgot the tm_gmtoff field.

Regards,

-- 
  Nicolas George

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 185 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Time stamp module floating around?
  2007-01-21  9:24   ` Nicolas George
@ 2007-01-21  9:53     ` Robert Roessler
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Roessler @ 2007-01-21  9:53 UTC (permalink / raw)
  To: Caml mailing list

Nicolas George wrote:
> Le duodi 2 pluviôse, an CCXV, skaller a écrit :
>> //Timestamp: 2007/1/12 18:36:37 UTC
> 
> I would strongly advise you tu use fixed-length fields with leading zeros:
> the big advantage of using the year-month-day order, instead of
> month-day-year or day-month-year, is that the lexical order of the string is
> the same as the chronological order of the date. Using variable-length
> fields breaks this. Furthermore, it makes it harder to parse the timestamp.
> 
> On the other hand, it is important not to forget "UTC".
> 
> While I am at it, I believe that yyyy-mm-dd is a more common format as
> yyyy/mm/dd.

Indeed... it is called ISO 8601. :)

Robert Roessler
roessler@rftp.com
http://www.rftp.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-01-21  9:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-21  2:42 Time stamp module floating around? Denis Bueno
2007-01-21  3:48 ` [Caml-list] " Chris King
2007-01-21  8:43 ` skaller
2007-01-21  9:24   ` Nicolas George
2007-01-21  9:53     ` Robert Roessler

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