Allow control over return type of parse_duration #64
+18
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My main suggested edit here is to allow control over the return type of
parse_duration
(implemented as a non-breaking revision). I explain below why I feel this is important. I also fixed a typo and changed an if-else block to its logical equivalent, so it is clear that it follows the same reasoning as another if-else block (line 218 onwards).Why do I feel control over the return type of
parse_duration
is important?The underlying issue at play here is the interpretation of the nominal duration "P1D" as an absolute duration
datetime.timedelta(days=1)
. That is, adatetime.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.If you'd like, I can make a ticket for this, too, but I'd like to restrict this PR to merely allowing control over the return type. By setting
as_timedelta_if_possible=False
, theisodate.Duration
could be used to determine the exact duration of nominal durations by their position in a calendar. For example, usingpandas.DateOffset
(which is based ondateutil.relativedelta.relativedelta
):