Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of negative time deltas (#173)
Fixes #18. Fixes #171. The [Python docs say](https://docs.python.org/3/library/datetime.html#datetime.timedelta): > String representations of [timedelta](https://docs.python.org/3/library/datetime.html#datetime.timedelta) objects are normalized similarly to their internal representation. This leads to somewhat unusual results for negative timedeltas. For example: ```pycon >>> timedelta(hours=-5) datetime.timedelta(days=-1, seconds=68400) >>> print(_) -1 day, 19:00:00 ``` However, we assumed all components have the same sign, and used absolute values of some of those, leading to inconsistent behaviour (on Linux and macOS; it still worked on Windows). Instead, we should convert the whole `timedelta` into its absolute value, and then use its components directly. Also test all the `timedelta`s with positive and negative values.
- Loading branch information
Showing
3 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters