Skip to content

Commit 8f975c4

Browse files
Add chained offset logic for FCP (#5885)
1 parent d0cdbc2 commit 8f975c4

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

changes.d/5885.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed bug in using a final cycle point with chained offsets e.g. 'final cycle point = +PT6H+PT1S'.

cylc/flow/cycling/iso8601.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,23 @@ def get_dump_format():
895895
def get_point_relative(offset_string, base_point):
896896
"""Create a point from offset_string applied to base_point."""
897897
try:
898-
interval = ISO8601Interval(str(interval_parse(offset_string)))
898+
operator = '+'
899+
base_point_relative = base_point
900+
for part in re.split(r'(\+|-)', offset_string):
901+
if part == '+' or part == '-':
902+
operator = part
903+
elif part != '':
904+
interval = interval_parse(part)
905+
if operator == '-':
906+
interval *= -1
907+
base_point_relative += ISO8601Interval(str(interval))
908+
return base_point_relative
899909
except IsodatetimeError:
910+
# It's a truncated time point rather than an interval
900911
return ISO8601Point(str(
901912
WorkflowSpecifics.abbrev_util.parse_timepoint(
902913
offset_string, context_point=point_parse(base_point.value))
903914
))
904-
else:
905-
return base_point + interval
906915

907916

908917
def interval_parse(interval_string):

tests/unit/test_config.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,17 @@ def test_process_startcp(
532532
None,
533533
id="Relative fcp"
534534
),
535+
pytest.param(
536+
ISO8601_CYCLING_TYPE,
537+
{
538+
'initial cycle point': '2017-02-11',
539+
'final cycle point': '+P4D+PT3H-PT2H',
540+
},
541+
None,
542+
'20170215T0100+0530',
543+
None,
544+
id="Relative fcp chained"
545+
),
535546
pytest.param(
536547
ISO8601_CYCLING_TYPE,
537548
{
@@ -1429,11 +1440,7 @@ def test_zero_interval(
14291440
('1988-02-29', '+P1M+P1Y', '1989-03-29'),
14301441
('1910-08-14', '+P2D-PT6H', '1910-08-15T18:00'),
14311442
('1850-04-10', '+P1M-P1D+PT1H', '1850-05-09T01:00'),
1432-
pytest.param(
1433-
'1066-10-14', '+PT1H+PT1M', '1066-10-14T01:01',
1434-
marks=pytest.mark.xfail
1435-
# https://github.com/cylc/cylc-flow/issues/5047
1436-
),
1443+
('1066-10-14', '+PT1H+PT1M', '1066-10-14T01:01'),
14371444
]
14381445
)
14391446
def test_chain_expr(

0 commit comments

Comments
 (0)