1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
include Timmy.Timezone
module Js = Js_of_ocaml.Js
let now () = Ptime_clock.now () |> Timmy.Time.of_ptime
let timezone_local =
let offset_calendar_time_s ~date:(year, month, day)
~time:(hours, minutes, seconds) =
let () =
let is_input_ok =
Result.is_ok (Timmy.Date.of_tuple (year, month, day))
&& Result.is_ok (Timmy.Daytime.of_tuple (hours, minutes, seconds))
in
match is_input_ok with
| true -> ()
| false ->
Fmt.failwith
"Given date and time %04i-%02i-%02i at %02i:%02i:%02i are not valid"
year month day hours minutes seconds
in
let js_date =
new%js Js.date_sec year (month - 1) day hours minutes seconds
in
js_date##getTimezoneOffset * 60 * -1
and offset_timestamp_s ~unix_timestamp =
let () =
if Int64.compare 0L unix_timestamp > 0 then
Fmt.failwith "Given timestamp is negative"
in
let js_date =
new%js Js.date_fromTimeValue (Int64.to_float unix_timestamp *. 1000.0)
in
js_date##getTimezoneOffset * 60 * -1
in
of_implementation ~offset_calendar_time_s ~offset_timestamp_s
let today () = Timmy.Date.of_time ~timezone:timezone_local @@ now ()