birl icon indicating copy to clipboard operation
birl copied to clipboard

Comparisons between naive times do not account for TimeOfDay value

Open jrstrunk opened this issue 1 year ago • 1 comments

Thanks for the package, I've gotten lots of use out of it! One thing I noticed is that running this code:

  let assert Ok(t1) = birl.parse("2019-01-01T14:00:00.000-04:00")
  let assert Ok(t2) = birl.parse("2019-01-01T14:00:00.001-04:00")
  birl.compare(t1, t2)
  |> io.debug

will result in Lt, while running this code:

  let assert Ok(t1) = birl.parse("2019-01-01T14:00:00.000")
  let assert Ok(t2) = birl.parse("2019-01-01T14:00:00.001")
  birl.compare(t1, t2)
  |> io.debug

will result in Eq, and this code:

  let assert Ok(t1) = birl.parse("2019-01-01T14:00:00.000")
  let assert Ok(t2) = birl.parse("2019-01-02T14:00:00.001")
  birl.compare(t1, t2)
  |> io.debug

will result in Lt.

It seems to me like the time of day should still be considered when comparing naive times, not just the calendar date.

If you want to preserve the original functionality of only comparing the calendar date, maybe another function should be added like compare_date. I can implement it if the maintainer agrees, any thoughts?

jrstrunk avatar May 18 '24 15:05 jrstrunk

This is a bug but not in the comparison feature. parse should not accept a string that does not have an offset. It seems like the parse function has several bugs and I need to find the time to make a complete overhaul. Thanks for the issue

massivefermion avatar May 18 '24 15:05 massivefermion