jiff: Inconsistency: Are days 24 hours or not?

There seems to be some inconsistency in the treatment of days in spans. In particular, TryFrom<Span> for Duration assumes that days are 24 hours, whereas Timestamp::saturating_add rejects days as units that can’t be resolved without a specific timezone.

Personaly I think the assumption that days are 24 hours is dangerous and shouldn’t be made (because it is readily violated by DST), but more than that I think all functions should at least agree on whether days are assumed to always be 24 hours or not.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I could see, for example, not realizing that you need to provide a relative datetime to round, trying it and then relying on it to produce an error if you’re doing something wrong. Since it’s silent about days, you assume it’s okay and go on to do something with those durations and time zone aware datetimes.

That is definitely an issue that I could see happening, though my specific situation was a little different.

Basically I am parsing and processing some data dumps from some event logs. The documentation on the data format is limited, so I want to validate everything as strictly as possible. As part of that I want to enforce that there must be no ambiguity about the duration of spans. If there ever was ambiguity (e.g. if the event logs contained a span with days) then I would have to figure out what that actually means. The zoned datetimes only come into play because I later summarize the data in my local timezone (which has DST).

But had round given you an error, I think your remedy would have been to use a zoned relative datetime with round and thereby get correct spans. Is that right?

Not quite. If there is ambiguity about the duration of the spans then something is wrong with the input data and I will need to dig deeper into what that means. I am assuming that the durations will never contain ambiguous units like days or months, but I don’t know for sure, so my goal with rounding without providing a zoned datetime was to enforce that if my assumption turns out to be wrong I will get an error.