From 07ba5def6030ed9ae9d3604cfa7c8c90b92cfce2 Mon Sep 17 00:00:00 2001 From: David Sutherland Date: Fri, 18 Oct 2024 12:13:53 +1300 Subject: [PATCH] fix CPF wall_clock offset precision constraint --- cylc/flow/cycling/iso8601.py | 18 +++++++++++------- cylc/flow/task_proxy.py | 15 ++++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cylc/flow/cycling/iso8601.py b/cylc/flow/cycling/iso8601.py index 3d7cf42bc3e..e7c3750e5bb 100644 --- a/cylc/flow/cycling/iso8601.py +++ b/cylc/flow/cycling/iso8601.py @@ -952,28 +952,32 @@ def _interval_parse(interval_string): return WorkflowSpecifics.interval_parser.parse(interval_string) -def point_parse(point_string: str) -> 'TimePoint': - """Parse a point_string into a proper TimePoint object.""" +def point_parse( + point_string: str, dump_format: Optional[str] = None +) -> 'TimePoint': + """Parse a point_string into a proper format specific TimePoint object.""" + if dump_format is None: + dump_format = WorkflowSpecifics.DUMP_FORMAT return _point_parse( point_string, - WorkflowSpecifics.DUMP_FORMAT, + dump_format, WorkflowSpecifics.ASSUMED_TIME_ZONE ) @lru_cache(10000) -def _point_parse(point_string: str, _dump_fmt, _tz) -> 'TimePoint': +def _point_parse(point_string: str, dump_fmt, _tz) -> 'TimePoint': """Parse a point_string into a proper TimePoint object. Args: point_string: The string to parse. - _dump_fmt: Dump format (only used to avoid invalid cache hits). + dump_fmt: Dump format (used to avoid invalid cache hits). _tz: Cycle point time zone (only used to avoid invalid cache hits). """ - if "%" in WorkflowSpecifics.DUMP_FORMAT: + if "%" in dump_fmt: # May be a custom not-quite ISO 8601 dump format. with contextlib.suppress(IsodatetimeError): return WorkflowSpecifics.point_parser.strptime( - point_string, WorkflowSpecifics.DUMP_FORMAT) + point_string, dump_fmt) # Attempt to parse it in ISO 8601 format. return WorkflowSpecifics.point_parser.parse(point_string) diff --git a/cylc/flow/task_proxy.py b/cylc/flow/task_proxy.py index 4e7b60d6e0a..688a8811b28 100644 --- a/cylc/flow/task_proxy.py +++ b/cylc/flow/task_proxy.py @@ -48,7 +48,6 @@ from cylc.flow.cycling.iso8601 import ( point_parse, interval_parse, - ISO8601Interval ) if TYPE_CHECKING: @@ -427,11 +426,17 @@ def get_clock_trigger_time( if offset_str == 'P0Y': trigger_time = point else: - trigger_time = point + ISO8601Interval(offset_str) + trigger_time = ( + point_parse(str(point), '%Y%m%dT%H%M%S') + + interval_parse(offset_str) + ) - offset = int( - point_parse(str(trigger_time)).seconds_since_unix_epoch) - self.clock_trigger_times[offset_str] = offset + self.clock_trigger_times[offset_str] = int( + point_parse( + str(trigger_time), + '%Y%m%dT%H%M%S' + ).seconds_since_unix_epoch + ) return self.clock_trigger_times[offset_str] def get_try_num(self):