Skip to content

Commit

Permalink
Explicit float conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Oct 6, 2023
1 parent d839cac commit 1ed2318
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/os_date.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,20 @@ let to_utc ?(timezone = user_tz ()) d =

let%client to_local d =
let d = CalendarLib.Calendar.to_unixfloat d in
let o = (new%js Js.date_fromTimeValue (d *. 1000.))##getTimezoneOffset in
let o =
(new%js Js.date_fromTimeValue (Js.float (d *. 1000.)))##getTimezoneOffset
in
CalendarLib.Calendar.from_unixfloat (d -. (float o *. 60.))

let%client to_utc d =
let d = CalendarLib.Calendar.to_unixfloat d in
let o = (new%js Js.date_fromTimeValue (d *. 1000.))##getTimezoneOffset in
let o =
(new%js Js.date_fromTimeValue (Js.float (d *. 1000.)))##getTimezoneOffset
in
let d' = d +. (float o *. 60.) in
let o' = (new%js Js.date_fromTimeValue (d' *. 1000.))##getTimezoneOffset in
let o' =
(new%js Js.date_fromTimeValue (Js.float (d' *. 1000.)))##getTimezoneOffset
in
CalendarLib.Calendar.from_unixfloat
(if o = o'
then d' (* We guessed the DST status right *)
Expand Down

0 comments on commit 1ed2318

Please sign in to comment.