Skip to content

Commit

Permalink
Explicit float conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Sep 20, 2024
1 parent 3278171 commit 97955f3
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 @@ -141,14 +141,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 97955f3

Please sign in to comment.