Skip to content

Fix CLI offset bug - #295

Merged
MetRonnie merged 7 commits into
metomi:masterfrom
MetRonnie:cli-offset-bug
Nov 24, 2026
Merged

MetRonnie merged 7 commits into
metomi:masterfrom
MetRonnie:cli-offset-bug

Conversation

@MetRonnie

@MetRonnie MetRonnie commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Repro

$ isodatetime 20260101T0000 20260101T0050
PT5M

Expected behaviour

PT50M

@MetRonnie MetRonnie added this to the 3.x milestone Nov 20, 2026
@MetRonnie MetRonnie self-assigned this Nov 20, 2026
@MetRonnie
MetRonnie requested a balanced review from Copilot November 20, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the CLI offset parsing fix.

No open issues 🎉

What changed in this PR

This PR addresses a CLI offset bug by removing ISO 8601 formats from DateTimeOperator’s fallback parsing formats and updating its tests.

Changes:

  • Retains only ctime and Unix date formats in PARSE_FORMATS.
  • Converts datetime operator tests to parametrized pytest functions and adds a year-only time-point difference case.
File Description
metomi/​isodatetime/​tests/​test_datetimeoper.py Migrates tests to pytest and adds coverage for year-only input.
metomi/​isodatetime/​datetimeoper.py Removes ISO 8601 fallback formats, makes the format collection a tuple, and simplifies the class declaration.

Review effort: Balanced

Comment on lines -43 to -44
"%Y-%m-%dT%H:%M:%S", # ISO8601, extended
"%Y%m%dT%H%M%S", # ISO8601, basic

@MetRonnie MetRonnie Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These two shouldn't be needed, because if strptime fails on all of these formats, it tries the time point parser instead which covers these formats anyway.

for parse_format in self.PARSE_FORMATS:
try:
time_point = self.strptime(time_point_str, parse_format)
break
except ValueError:
pass
if time_point is None:
time_point = self.time_point_parser.parse(
time_point_str,
dump_as_parsed=True)

The bug came from strptime and the ...%H%M%S format - it considers 0050 to be 0 hours, 5 mins, 0 secs.

@MetRonnie MetRonnie modified the milestones: 3.x, 3.2.1 Nov 20, 2026
@MetRonnie
MetRonnie requested review from samuel-denton and a lite review from Copilot November 20, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change removes ambiguous ISO fallback formats and adds regression coverage for compact timestamp differences and duration behavior, with no active review issues reported.

No open issues 🎉

Review effort: Lite

@samuel-denton samuel-denton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, repro and test both pass on this branch and fail on master.

@samuel-denton

Copy link
Copy Markdown

One review ok here? Small change but potentially big impact if it's wrong I guess.

@MetRonnie

Copy link
Copy Markdown
Contributor Author

I'm confident with a single review (plus Copilot) for this one (2 in an ideal world, but we're too stretched to give every PR 2 reviews at the moment)

@MetRonnie
MetRonnie merged commit 516bec5 into metomi:master Nov 24, 2026
8 checks passed
@MetRonnie
MetRonnie deleted the cli-offset-bug branch November 24, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants