10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-06-01 19:05:17 +02:00
qmcchem/ocaml/Time.ml
2019-07-22 11:51:14 +02:00

51 lines
1.1 KiB
OCaml

let of_sec s =
Unix.gmtime s
let to_sec t =
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
and mday = t.Unix.tm_mday
in
sec +
min * 60 +
hour * 60 * 60 +
mday * 60 * 60 * 24
let string_of_t t =
let mday = t.Unix.tm_mday in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour + 24*mday
in
Printf.sprintf "%2d:%2d:%2d" hour min sec
let string_of_date t =
let year = 1900 + t.Unix.tm_year in
let mon = t.Unix.tm_mon in
let mday = t.Unix.tm_mday in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
in
let month =
match mon with
| 0 -> "Jan" | 1 -> "Feb" | 2 -> "Mar" | 3 -> "Apr"
| 4 -> "May" | 5 -> "Jun" | 6 -> "Jul" | 7 -> "Aug"
| 8 -> "Sep" | 9 -> "Oct" | 10 -> "Nov" | 11 -> "Dec"
| _ -> assert false
in
Printf.sprintf "%2d %3s %4d - %2.2d:%2.2d:%2.2d" mday month year hour min sec
let string_of_now () =
Unix.time ()
|> Unix.localtime
|> string_of_date
let string_of_sec s =
of_sec s
|> string_of_t