Skip to content

Commit

Permalink
Fall back to UTC time on time zone errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreryan committed Dec 3, 2022
1 parent 7108071 commit 0d34875
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ let redirect_out_err out proc = Sh.outputs_to ~append:() out proc

let eval_sh log proc = Sh.eval @@ redirect_out_err log proc

(** On systems without the local timezone set up properly (e.g., alpine linux
docker images), we fallback to UTC timezone. *)
let zone () =
try Lazy.force Time_unix.Zone.local with Sys_error _ -> Time_unix.Zone.utc

let now_coarse () =
let zone = Lazy.force Time_unix.Zone.local in
let now = Time.now () in
Time_unix.format now "%Y-%m-%d %H:%M:%S" ~zone
Time_unix.format now "%Y-%m-%d %H:%M:%S" ~zone:(zone ())

let now () =
let zone = Lazy.force Time_unix.Zone.local in
Time.to_filename_string ~zone @@ Time.now ()
let now () = Time.to_filename_string ~zone:(zone ()) @@ Time.now ()

let log_name ~log_base ~desc =
let now = now () in
Expand Down

0 comments on commit 0d34875

Please sign in to comment.