From: Richard W.M. Jones Date: Thu, 23 Feb 2012 22:24:29 +0000 (+0000) Subject: Move string_of_time_t to Whenutils module. X-Git-Tag: 0.0.4~9 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=adc311d69459345a9ce23864d7aa41a7a6b97b42;p=whenjobs.git Move string_of_time_t to Whenutils module. This is just code motion. --- diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 42c32de..ddbb9cd 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -285,12 +285,6 @@ and delete_timer_group () = Unixqueue.clear esys g; timer_group := None -and string_of_time_t t = - let tm = gmtime t in - sprintf "%04d-%02d-%02d %02d:%02d:%02d UTC" - (1900+tm.tm_year) (1+tm.tm_mon) tm.tm_mday - tm.tm_hour tm.tm_min tm.tm_sec - and run_job job = (* Increment JOBSERIAL. *) let serial = diff --git a/lib/whenutils.ml b/lib/whenutils.ml index 7d20f75..583d030 100644 --- a/lib/whenutils.ml +++ b/lib/whenutils.ml @@ -50,3 +50,10 @@ let rec filter_map f = function match f x with | Some y -> y :: filter_map f xs | None -> filter_map f xs + +let string_of_time_t ?(localtime = false) t = + let tm = (if localtime then Unix.localtime else gmtime) t in + sprintf "%04d-%02d-%02d %02d:%02d:%02d%s" + (1900+tm.tm_year) (1+tm.tm_mon) tm.tm_mday + tm.tm_hour tm.tm_min tm.tm_sec + (if localtime then "" else " UTC") diff --git a/lib/whenutils.mli b/lib/whenutils.mli index 7a69d44..61cd4f8 100644 --- a/lib/whenutils.mli +++ b/lib/whenutils.mli @@ -123,3 +123,7 @@ val isalnum : char -> bool val filter_map : ('a -> 'b option) -> 'a list -> 'b list (** Filter + map. *) + +val string_of_time_t : ?localtime:bool -> float -> string +(** Convert string to time in ISO format. If [~localtime] is true + then it uses localtime, else UTC. *)