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

Review iso8601.py code comments (and code?) #4805

Closed
MetRonnie opened this issue Apr 6, 2022 · 4 comments · Fixed by #4943
Closed

Review iso8601.py code comments (and code?) #4805

MetRonnie opened this issue Apr 6, 2022 · 4 comments · Fixed by #4943
Assignees
Labels
could be better Not exactly a bug, but not ideal. investigation
Milestone

Comments

@MetRonnie
Copy link
Member

There are several cryptic comments such as

# correct for year in 'now' if year only,
# or year and time, specified in input
if re.search(r"\(-\d{2}[);T]", value):
now.year += 1
# correct for month in 'now' if year and month only,
# or year, month and time, specified in input
elif re.search(r"\(-\d{4}[);T]", value):
now.month_of_year += 1

# ensure month and day from 'now' are not included
# where they did not appear in the truncated datetime
# NOTE: this may break when the order of tick over
# for time point is reversed!!!
# https://github.com/metomi/isodatetime/pull/101
# case 1 - year only
if re.search(r"\(-\d{2}[);T]", value):
cycle_point.month_of_year = 1
cycle_point.day_of_month = 1
# case 2 - month only or year and month
elif re.search(r"\(-(-\d{2}|\d{4})[;T)]", value):
cycle_point.day_of_month = 1

In the latter, unfortunately the linked PR metomi/isodatetime#101 is not very illuminating to me! (And the discussion there appears as if it might be suffering from confusion over the "addition of truncated TimePoint" bug metomi/isodatetime#80, to boot)

Also, is it just me or are the regexes in the code alarmingly simple? We should see if we can find faults in them.

@MetRonnie MetRonnie added could be better Not exactly a bug, but not ideal. investigation labels Apr 6, 2022
@MetRonnie MetRonnie added this to the cylc-8.0rc4 milestone Apr 6, 2022
@hjoliver
Copy link
Member

hjoliver commented Apr 6, 2022

Maybe the authors of those comments will remember. The first were by @lhuggett ; the second by @oliver-sanders .

@lhuggett
Copy link
Contributor

lhuggett commented Apr 6, 2022

So I think what the first one was about was that if you include the year (and/or month) from the real "now" when you're not looking at a day as well, you end up with a false earliness, so you move it (them) forward one to make sure the next/previous works correctly. I do recall that I only found it by trial and error.

For the second one, I'm afraid I don't remember what the issue was about the potential breakage from the reversing of tickover order, only that it was something that we thought could be a problem but hadn't actually been demonstrated as one at that point.

@oliver-sanders oliver-sanders modified the milestones: cylc-8.0rc4, cylc-8.x Apr 7, 2022
@MetRonnie
Copy link
Member Author

MetRonnie commented Apr 20, 2022

Thanks for the response, looks like the first one comes down to a possible bug in isodatetime:

>>> now = TimePointParser().parse("2010-08-08T15:40Z")
>>> point = TimePointParser(allow_truncated=True).parse("-10")
>>> now + point
<metomi.isodatetime.data.TimePoint: 2010-08-08T15:40:00Z>
>>> now == now + point
True

I think now + point ought to equal 2110-08-08T15:40:00Z. However this might be debatable

Possibly related to metomi/isodatetime#80

@MetRonnie
Copy link
Member Author

For the second, I think I have figured it out: metomi/isodatetime#212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
could be better Not exactly a bug, but not ideal. investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants