Skip to content

Commit 116e567

Browse files
committed
Update isodatetime to 3.2
Fix bug where `next(...)` could return past datetime
1 parent c07392d commit 116e567

File tree

6 files changed

+9
-40
lines changed

6 files changed

+9
-40
lines changed

conda-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- graphviz # for static graphing
1010
# Note: can't pin jinja2 any higher than this until we give up on Cylc 7 back-compat
1111
- jinja2 >=3.0,<3.1
12-
- metomi-isodatetime >=1!3.0.0, <1!3.2.0
12+
- metomi-isodatetime >=1!3.2.0, <1!3.3.0
1313
- packaging
1414
# Constrain protobuf version for compatible Scheduler-UIS comms across hosts
1515
- protobuf >=4.24.4,<4.25.0

cylc/flow/cycling/iso8601.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
from typing import List, Optional, TYPE_CHECKING, Tuple
2323

24-
from metomi.isodatetime.data import Calendar, CALENDAR, Duration
24+
from metomi.isodatetime.data import Calendar, CALENDAR
2525
from metomi.isodatetime.dumpers import TimePointDumper
2626
from metomi.isodatetime.timezone import (
2727
get_local_time_zone, get_local_time_zone_format, TimeZoneFormatMode)
@@ -699,14 +699,6 @@ def ingest_time(value: str, now: Optional[str] = None) -> str:
699699
now = get_current_time_string()
700700
now_point = parser.parse(now)
701701

702-
# correct for year in 'now' if year is the only date unit specified -
703-
# https://github.com/cylc/cylc-flow/issues/4805#issuecomment-1103928604
704-
if re.search(r"\(-\d{2}[);T]", value):
705-
now_point += Duration(years=1)
706-
# likewise correct for month if year and month are the only date units
707-
elif re.search(r"\(-\d{4}[);T]", value):
708-
now_point += Duration(months=1)
709-
710702
# perform whatever transformation is required
711703
offset = None
712704
if is_prev_next:
@@ -799,28 +791,6 @@ def prev_next(
799791

800792
cycle_point = timepoints[my_diff.index(min(my_diff))]
801793

802-
# ensure truncated dates do not have time from 'now' included' -
803-
# https://github.com/metomi/isodatetime/issues/212
804-
if 'T' not in value.split(')')[0]:
805-
# NOTE: Strictly speaking we shouldn't forcefully mutate TimePoints
806-
# in this way as they're meant to be immutable since
807-
# https://github.com/metomi/isodatetime/pull/165, however it
808-
# should be ok as long as the TimePoint is not used as a dict key and
809-
# we don't call any of the TimePoint's cached methods until after we've
810-
# finished mutating it.
811-
cycle_point._hour_of_day = 0
812-
cycle_point._minute_of_hour = 0
813-
cycle_point._second_of_minute = 0
814-
# likewise ensure month and day from 'now' are not included
815-
# where they did not appear in the truncated datetime
816-
if re.search(r"\(-\d{2}[);T]", value):
817-
# case 1 - year only
818-
cycle_point._month_of_year = 1
819-
cycle_point._day_of_month = 1
820-
elif re.search(r"\(-(-\d{2}|\d{4})[;T)]", value):
821-
# case 2 - month only or year and month
822-
cycle_point._day_of_month = 1
823-
824794
return cycle_point, offset
825795

826796

cylc/flow/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ def command_stop(
999999
# schedule shutdown after wallclock time passes provided time
10001000
parser = TimePointParser()
10011001
self.set_stop_clock(
1002-
int(parser.parse(clock_time).seconds_since_unix_epoch)
1002+
parser.parse(clock_time).seconds_since_unix_epoch
10031003
)
10041004
elif task is not None:
10051005
# schedule shutdown after task succeeds

cylc/flow/task_proxy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def get_point_as_seconds(self):
346346
"""Compute and store my cycle point as seconds since epoch."""
347347
if self.point_as_seconds is None:
348348
iso_timepoint = point_parse(str(self.point))
349-
self.point_as_seconds = int(iso_timepoint.seconds_since_unix_epoch)
349+
self.point_as_seconds = iso_timepoint.seconds_since_unix_epoch
350350
if iso_timepoint.time_zone.unknown:
351351
utc_offset_hours, utc_offset_minutes = (
352352
get_local_time_zone())
@@ -376,8 +376,7 @@ def get_clock_trigger_time(
376376
else:
377377
trigger_time = point + ISO8601Interval(offset_str)
378378

379-
offset = int(
380-
point_parse(str(trigger_time)).seconds_since_unix_epoch)
379+
offset = point_parse(str(trigger_time)).seconds_since_unix_epoch
381380
self.clock_trigger_times[offset_str] = offset
382381
return self.clock_trigger_times[offset_str]
383382

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ install_requires =
6868
graphene>=2.1,<3
6969
# Note: can't pin jinja2 any higher than this until we give up on Cylc 7 back-compat
7070
jinja2==3.0.*
71-
metomi-isodatetime>=1!3.0.0,<1!3.2.0
71+
metomi-isodatetime>=1!3.2.0,<1!3.3.0
7272
# Constrain protobuf version for compatible Scheduler-UIS comms across hosts
7373
packaging
7474
protobuf>=4.24.4,<4.25.0

tests/unit/cycling/test_iso8601.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def test_simple(set_cycling_type):
685685
('next(--0325)', '20110325T0000Z'),
686686
('next(---10)', '20100810T0000Z'),
687687
('next(---05T1200Z)', '20100905T1200Z'),
688-
param('next(--08-08)', '20110808T0000Z', marks=pytest.mark.xfail),
688+
('next(--08-08)', '20110808T0000Z'),
689689
('next(T15)', '20100809T1500Z'),
690690
('next(T-41)', '20100808T1541Z'),
691691
]
@@ -709,7 +709,7 @@ def test_next_simple(value: str, expected: str, set_cycling_type):
709709
('previous(--0325)', '20100325T0000Z'),
710710
('previous(---10)', '20100710T0000Z'),
711711
('previous(---05T1200Z)', '20100805T1200Z'),
712-
param('previous(--08-08)', '20100808T0000Z', marks=pytest.mark.xfail),
712+
('previous(--08-08)', '20100808T0000Z'),
713713
('previous(T15)', '20100808T1500Z'),
714714
('previous(T-41)', '20100808T1441Z'),
715715
]
@@ -856,7 +856,7 @@ def test_weeks_days(set_cycling_type):
856856
('previous(--1225)', '20171225T0000Z'),
857857
('next(-2006)', '20200601T0000Z'),
858858
('previous(-W101)', '20180305T0000Z'),
859-
('next(-W-1; -W-3; -W-5)', '20180314T0000Z'),
859+
('next(-W-1; -W-3; -W-5)', '20180316T0000Z'),
860860
('next(-001; -091; -181; -271)', '20180401T0000Z'),
861861
('previous(-365T12Z)', '20171231T1200Z'),
862862
]

0 commit comments

Comments
 (0)