hroptatyr / dateutils

nifty command line date and time utilities; fast date calculations and conversion in the shell
http://www.fresse.org/dateutils/
Other
616 stars 42 forks source link

What is datediff's expected behavior w.r.t. Daylight Saving Time changes? #129

Closed mattdm closed 3 years ago

mattdm commented 3 years ago

I grew up in Indiana, long enough ago that we didn't have to deal with this nonsense. But alas, madness seems to be almost universal. So:

$ date -d "2021-03-14 1:59"
Sun Mar 14 01:59:00 AM EST 2021

$ date -d "2021-03-14 2:00"
date: invalid date ‘2021-03-14 2:00’

$ date -d "2021-03-14 3:00"
Sun Mar 14 03:00:00 AM EDT 2021

... but:

$ datediff "2021-03-14 1:59" "2021-03-14 3:00"
3660s

I guess an alternate way of asking this is: what timezone does datediff assume when one isn't explicitly given? My naïve expectation was that it'd follow the timezone set in my environment, including handling DST transitions.

hroptatyr commented 3 years ago

Hi Matt, the timezone that's used by default is UTC. And you're right you'd have to specify it explicitly

$ datediff --from-zone America/New_York "2021-03-14 1:59" "2021-03-14 3:00"
60s

The opposite is more interesting

$ datediff --from-zone America/New_York "2021-11-07 1:59" "2021-11-07 2:00"
3660s

and there is no way (as per ISO 8601 and hence dateutils) to specify which one of the two 2 o'clocks you're referring to.

mattdm commented 3 years ago

Thanks! I guess probably the concrete thing here is that it'd be nice to have this information (UTC) in the man page, and perhaps also the example.

hroptatyr commented 3 years ago

I followed your suggestion and mentioned the special treatment of some zones, and UTC in particular. I'm ready to roll a new release, if not by this week then by the next.