diff --git a/lib/utils.ml b/lib/utils.ml index 48fc9ed..77d40b7 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -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