Skip to content

Fix truncated timepoint addition bug #234

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

Merged
merged 20 commits into from
May 8, 2025

Conversation

MetRonnie
Copy link
Contributor

@MetRonnie MetRonnie commented Jul 25, 2023

Closes #80
Closes #212

Built on #203

  • Tests included
  • Changelog entry included

@MetRonnie MetRonnie added the bug label Jul 25, 2023
@MetRonnie MetRonnie added this to the 3.1.0 milestone Jul 25, 2023
@MetRonnie MetRonnie self-assigned this Jul 25, 2023
@MetRonnie
Copy link
Contributor Author

Note this does not fix cylc/cylc-flow#2382, presumably that is still a bug in cylc-flow

@MetRonnie
Copy link
Contributor Author

Actually which should the behaviour be?

2019-01-15 + --01-15 = ?
  1. 2019-01-15 - same point (current behaviour)
  2. 2020-01-15 - next matching point (what I think it should be)

@MetRonnie MetRonnie force-pushed the truncated-timepoint-bug branch from 681b125 to 2833ad2 Compare July 27, 2023 18:30
@MetRonnie MetRonnie marked this pull request as draft August 11, 2023 10:28
@MetRonnie

This comment was marked as outdated.

@MetRonnie MetRonnie modified the milestones: 3.1.0, 3.2.0 Oct 4, 2023
@MetRonnie
Copy link
Contributor Author

MetRonnie commented Oct 19, 2023

Actually which should the behaviour be?

2019-01-15 + --01-15 = ?
  1. 2019-01-15 - same point (current behaviour)
  2. 2020-01-15 - next matching point (what I think it should be)

I think we have to maintain the current behaviour to avoid breaking next() in Cylc workflows - see cylc/cylc-flow#5777

(Technically we could change the behaviour here and add a workaround in Cylc, but that's more effort)

@MetRonnie
Copy link
Contributor Author

MetRonnie commented Nov 2, 2023

Decision on 2019-01-15 + --01-15 (with greater clarity and precision):

The behaviour is to be:

2019-01-15T00:00:00 + --01-15
>>> 2019-01-15T00:00:00  # same datetime (we are exactly at midnight)

2019-01-15T00:00:01 + --01-15
>>> 2020-01-15T00:00:00  # next year 

This is because a truncated datetime should assume 0 for any unspecified time units, and 1 for any unspecified date units lower than what has been specified.

@MetRonnie MetRonnie force-pushed the truncated-timepoint-bug branch 3 times, most recently from fb0a2f0 to 2f75c13 Compare January 16, 2024 16:44
@MetRonnie MetRonnie marked this pull request as ready for review January 16, 2024 17:07
@MetRonnie MetRonnie force-pushed the truncated-timepoint-bug branch from 02d8e73 to 6d6b7ee Compare January 22, 2024 18:58
@MetRonnie MetRonnie requested a review from wxtim February 29, 2024 16:23
Copy link
Contributor

@wxtim wxtim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, code looks good and looks like it fixes the bug. Is it worth filling the gaps in the coverage whilst you're at it. I think it is.

@MetRonnie MetRonnie force-pushed the truncated-timepoint-bug branch from 7e4b9b7 to 96e7f06 Compare March 7, 2024 14:03
@MetRonnie MetRonnie requested a review from wxtim March 7, 2024 16:09
Copy link
Contributor

@wxtim wxtim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I failed to approve sooner. Please get a second reviewer or merge as you think appropriate.

@MetRonnie
Copy link
Contributor Author

No worries, this has not been a top priority at the moment

@MetRonnie
Copy link
Contributor Author

@oliver-sanders Poke (I just spent half a day investigating a bug with Cylc initial cycle point = next(---01) with a non-UTC timezone only to find it is fixed by this PR)

@oliver-sanders
Copy link
Member

Sorry, this hasn't made the priority list.

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm happy with the new method, makes sense, very thorough.

There's a disparity in how input types are handled in a lot of these methods when if not isinstance(self, X): raise NotImplementedError is used. Some specify the one valid type, others pick the looser object (the latter is technically correct and more compatible with inheritance, although we probably wouldn't have written it that way if starting anew).

Comment on lines +1306 to +1326
def seconds_since_unix_epoch(self) -> int:
reference_timepoint = TimePoint(
**CALENDAR.UNIX_EPOCH_DATE_TIME_REFERENCE_PROPERTIES)
days, seconds = (self - reference_timepoint).get_days_and_seconds()
# N.B. This needs altering if we implement leap seconds.
return str(int(CALENDAR.SECONDS_IN_DAY * days + seconds))
return int(CALENDAR.SECONDS_IN_DAY * days + seconds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is why it is listed as such in the changelog

@MetRonnie MetRonnie mentioned this pull request Apr 30, 2025
@oliver-sanders
Copy link
Member

oliver-sanders commented May 7, 2025

Testing this out with cylc-flow.

Have found one Cylc unit test that fails with this branch:

FAILED tests/unit/cycling/test_iso8601.py::test_user_guide_examples[next(-W-1; -W-3; -W-5)-20180314T0000Z] - AssertionError: assert '20180316T0000Z' == '20180314T0000Z'

Should check whether this change is correct.

Otherwise, all good.

@MetRonnie
Copy link
Contributor Author

See cylc/cylc-flow#5928

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz squash merge.

@MetRonnie MetRonnie force-pushed the truncated-timepoint-bug branch from 68b9a4f to dfe5495 Compare May 8, 2025 17:00
@MetRonnie
Copy link
Contributor Author

MetRonnie commented May 8, 2025

(Latest force push only affects changelog as per review request)

(Edit: argh, accidentally pressed normal merge instead of squash, oh well)

@MetRonnie MetRonnie merged commit 48ff9cb into metomi:master May 8, 2025
8 checks passed
@MetRonnie MetRonnie deleted the truncated-timepoint-bug branch May 8, 2025 17:02
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.

Inconsistency between truncated dates and truncated times Day of the month inconsistency with truncated time points
3 participants