Move string_of_time_t to Whenutils module.
[whenjobs.git] / lib / whenutils.ml
index 7d20f75..583d030 100644 (file)
@@ -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
     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")