New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt formatter for ISO durations #459
Conversation
Signed-off-by: F.N. Claessen <felix@seita.nl>
Pull Request Test Coverage Report for Build 2715104497
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess your point is that timedelta(days=1)
has no defined duration, so there can be no "PXD" formatting from that ― the only correct way to treat this is to assume 24h. Is that right?
This seems to work. My only request would be to add a test with assumptions like I tried below, but if we regard this as temporary until isodate fixes it, that is not needed.
In [2]: from flexmeasures.utils.time_utils import duration_isoformat
In [3]: from datetime import timedelta
In [4]: duration_isoformat(timedelta(hours=1))
Out[4]: 'PT1H'
In [5]: duration_isoformat(timedelta(hours=14))
Out[5]: 'PT14H'
In [6]: duration_isoformat(timedelta(hours=24))
Out[6]: 'PT24H'
In [7]: duration_isoformat(timedelta(days=1))
Out[7]: 'PT24H'
In [8]: duration_isoformat(timedelta(days=1, seconds=22))
Out[8]: 'PT24H22S'
In [9]: duration_isoformat(timedelta(days=1, seconds=122))
Out[9]: 'PT24H2M2S'
In [10]: from isodate import duration_isoformat as orig_duration_isoformat
In [11]: orig_duration_isoformat(timedelta(hours=1))
Out[11]: 'PT1H'
In [12]: orig_duration_isoformat(timedelta(hours=14))
Out[12]: 'PT14H'
In [13]: orig_duration_isoformat(timedelta(hours=24))
Out[13]: 'P1D'
In [14]: orig_duration_isoformat(timedelta(days=1))
Out[14]: 'P1D'
In [15]: orig_duration_isoformat(timedelta(days=1, seconds=22))
Out[15]: 'P1DT22S'
In [16]: orig_duration_isoformat(timedelta(days=1, seconds=122))
Out[16]: 'P1DT2M2S'
I think that is the right conclusion from the wrong point. Good idea to add those tests. |
Signed-off-by: F.N. Claessen <felix@seita.nl>
# Conflicts: # documentation/changelog.rst
# Conflicts: # documentation/changelog.rst
This PR implements a workaround for an issue I raised with the isodate maintainer(s).