Skip to content

Commit

Permalink
Add chained offset logic for FCP (#5885)
Browse files Browse the repository at this point in the history
  • Loading branch information
markgrahamdawson authored Dec 19, 2023
1 parent d0cdbc2 commit 8f975c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes.d/5885.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug in using a final cycle point with chained offsets e.g. 'final cycle point = +PT6H+PT1S'.
15 changes: 12 additions & 3 deletions cylc/flow/cycling/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,23 @@ def get_dump_format():
def get_point_relative(offset_string, base_point):
"""Create a point from offset_string applied to base_point."""
try:
interval = ISO8601Interval(str(interval_parse(offset_string)))
operator = '+'
base_point_relative = base_point
for part in re.split(r'(\+|-)', offset_string):
if part == '+' or part == '-':
operator = part
elif part != '':
interval = interval_parse(part)
if operator == '-':
interval *= -1
base_point_relative += ISO8601Interval(str(interval))
return base_point_relative
except IsodatetimeError:
# It's a truncated time point rather than an interval
return ISO8601Point(str(
WorkflowSpecifics.abbrev_util.parse_timepoint(
offset_string, context_point=point_parse(base_point.value))
))
else:
return base_point + interval


def interval_parse(interval_string):
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,17 @@ def test_process_startcp(
None,
id="Relative fcp"
),
pytest.param(
ISO8601_CYCLING_TYPE,
{
'initial cycle point': '2017-02-11',
'final cycle point': '+P4D+PT3H-PT2H',
},
None,
'20170215T0100+0530',
None,
id="Relative fcp chained"
),
pytest.param(
ISO8601_CYCLING_TYPE,
{
Expand Down Expand Up @@ -1429,11 +1440,7 @@ def test_zero_interval(
('1988-02-29', '+P1M+P1Y', '1989-03-29'),
('1910-08-14', '+P2D-PT6H', '1910-08-15T18:00'),
('1850-04-10', '+P1M-P1D+PT1H', '1850-05-09T01:00'),
pytest.param(
'1066-10-14', '+PT1H+PT1M', '1066-10-14T01:01',
marks=pytest.mark.xfail
# https://github.com/cylc/cylc-flow/issues/5047
),
('1066-10-14', '+PT1H+PT1M', '1066-10-14T01:01'),
]
)
def test_chain_expr(
Expand Down

0 comments on commit 8f975c4

Please sign in to comment.