massivefermion / birl

datetime handling for gleam
https://hex.pm/packages/birl
Apache License 2.0
72 stars 9 forks source link

set_time_of_day does not set monotonic time value #34

Open michaeljones opened 5 months ago

michaeljones commented 5 months ago

I came across an issue where I tried to do:

let now = birl.now()
let start_time =
  birl.set_time_of_day(
    now,
    birl.TimeOfDay(hour: 8, minute: 0, second: 0, milli_second: 0),
  )
let diff = birl.difference(now, start_time)

But this always returns Duration(0) because set_time_of_day doesn't seem to change the monotonic_time and difference uses the monotonic_time if it can?

I'm afraid I'm not sure what the solution is. Possibly to set the monotonic time to None if it is not possible to calculate it from the new time of day.

I have worked around it by converting now to an iso8601 string and re-parsing it at which point it doesn't have a monotonic_time so the approach works.

massivefermion commented 4 months ago

Right now the monotonic time is just the time passed since the VM started. To implement this I should change it so that the momotonic time also indicates a specific moment.

ghivert commented 2 months ago

Coming here to say that I understand monotonic time indicates the time passed since VM started, but then, why using it in compare function? Currently, if two wall_time are different, but monotonic_time has a value, wall_time are not taken into account.

When creating a new date, I currently uses birl.to_unix |> birl.from_unix to make sure everything works as expected 🙂