package timmy-unix

  1. Overview
  2. Docs
Unix clock implementation for Timmy

Install

Dune Dependency

Authors

Maintainers

Sources

1.0.0.tar.gz
md5=8ff18d53b9432f7d944adc31230736ff
sha512=0395308f402131b0333a8ee94c878d78e7698573e1c6bc943911692003b8d81949598e524e7ce0c9438cd4a3cf6298a58a868b24df7b5a5e1342ea263bd51a60

doc/src/timmy-unix.clock/clock.ml.html

Source file clock.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let now () = Ptime_clock.now () |> Timmy.Time.of_ptime

external offset_calendar_time_s : int * int * int -> int * int * int -> int
  = "ocaml_timmy_offset_calendar_time_s"

external offset_timestamp_s : Int64.t -> int = "ocaml_timmy_offset_timestamp_s"

let timezone_local =
  let offset_calendar_time_s ~date ~time = offset_calendar_time_s date time
  and offset_timestamp_s ~unix_timestamp =
    let () =
      if Int64.compare 0L unix_timestamp > 0 then
        Fmt.failwith "Given timestamp is negative"
    in
    offset_timestamp_s unix_timestamp
  in
  Timmy.Timezone.of_implementation ~offset_calendar_time_s ~offset_timestamp_s

let today () = Timmy.Date.of_time ~timezone:timezone_local @@ now ()
OCaml

Innovation. Community. Security.