lanonna/pam/bin/utils.ml

21 lines
600 B
OCaml
Raw Normal View History

2024-03-16 09:34:29 +01:00
open Unix
let now () =
let current_time = time () in
let human_time = localtime current_time in
let year = 1900 + human_time.tm_year in
let month = human_time.tm_mon + 1 in
let day = human_time.tm_mday in
let hour = human_time.tm_hour in
let minute = human_time.tm_min in
let second = human_time.tm_sec in
Printf.sprintf "%04d-%02d-%02d %02d:%02d:%02d"
year month day hour minute second
let result_unpack = function | Ok o -> o | Error e -> e
2024-03-25 14:17:34 +01:00
let unhandled m = [%string "Runtime failure: unhandled %{Batteries.dump m}"] |> print_endline; exit 2
let one_second = 1_000_000L