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.
From https://github.com/gweis/isodate/pull/64:
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 theDuration
class. I believe this issue also touchesparse_duration
.Please let me know if this makes sense.