Skip to content
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

Merged
merged 5 commits into from Jul 21, 2022
Merged

Adapt formatter for ISO durations #459

merged 5 commits into from Jul 21, 2022

Conversation

Flix6x
Copy link
Contributor

@Flix6x Flix6x commented Jul 8, 2022

This PR implements a workaround for an issue I raised with the isodate maintainer(s).

Signed-off-by: F.N. Claessen <felix@seita.nl>
@Flix6x Flix6x added the API label Jul 8, 2022
@Flix6x Flix6x self-assigned this Jul 8, 2022
@coveralls
Copy link
Collaborator

coveralls commented Jul 8, 2022

Pull Request Test Coverage Report for Build 2715104497

  • 26 of 27 (96.3%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 67.572%

Changes Missing Coverage Covered Lines Changed/Added Lines %
flexmeasures/utils/time_utils.py 19 20 95.0%
Totals Coverage Status
Change from base Build 2715071258: 0.06%
Covered Lines: 7201
Relevant Lines: 10083

💛 - Coveralls

@Flix6x Flix6x marked this pull request as ready for review July 9, 2022 19:56
@Flix6x Flix6x requested a review from nhoening July 9, 2022 19:57
Copy link
Contributor

@nhoening nhoening left a 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'

@Flix6x
Copy link
Contributor Author

Flix6x commented Jul 21, 2022

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?

I think that is the right conclusion from the wrong point. datetime.timedelta(days=1) is defined as 24 hours, so it does have a defined absolute duration, whereas "P1D" is defined as a nominal day, so it doesn't have a defined absolute duration.

Good idea to add those tests.

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
# Conflicts:
#	documentation/changelog.rst
# Conflicts:
#	documentation/changelog.rst
@Flix6x Flix6x merged commit ed890c2 into main Jul 21, 2022
@Flix6x Flix6x deleted the P1D_is_not_PT24H branch July 21, 2022 22:45
@Flix6x Flix6x added this to the 0.11.0 milestone Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants