gweis / isodate

ISO 8601 date/time parser
BSD 3-Clause "New" or "Revised" License
155 stars 59 forks source link

Avoid formatting absolute durations as nominal durations #74

Open Flix6x opened 2 years ago

Flix6x commented 2 years ago

From https://github.com/gweis/isodate/pull/64:

A datetime.timedelta(days=1) is defined as exactly 24 hours, whereas ISO 8601 defines "P1D" as a calendar day, whose exact duration depends on its positioning in a calendar. For example, for the Europe/Amsterdam timezone (which happens to be my timezone), daylight saving time will start on March 28th 2021, which means March 28th in my calendar has 23 hours.

from datetime import timedelta
from isodate import duration_isoformat

print(duration_isoformat(timedelta(hours=24)))  # Outcome: P1D Expected: PT24H

If you'd like, I could try my hand at a PR, starting with introducing a new self.days attribute to express days as a nominal duration in the Duration class. I believe this issue also touches parse_duration.

Please let me know if this makes sense.