|
19 | 19 | import contextlib
|
20 | 20 | from functools import lru_cache
|
21 | 21 | import re
|
22 |
| -from typing import List, Optional, TYPE_CHECKING, Tuple |
| 22 | +from typing import ( |
| 23 | + TYPE_CHECKING, |
| 24 | + List, |
| 25 | + Optional, |
| 26 | + Tuple, |
| 27 | +) |
23 | 28 |
|
24 |
| -from metomi.isodatetime.data import Calendar, CALENDAR, Duration |
| 29 | +from metomi.isodatetime.data import ( |
| 30 | + CALENDAR, |
| 31 | + Calendar, |
| 32 | +) |
25 | 33 | from metomi.isodatetime.dumpers import TimePointDumper
|
26 |
| -from metomi.isodatetime.timezone import ( |
27 |
| - get_local_time_zone, get_local_time_zone_format, TimeZoneFormatMode) |
28 | 34 | from metomi.isodatetime.exceptions import IsodatetimeError
|
29 | 35 | from metomi.isodatetime.parsers import ISO8601SyntaxError
|
30 |
| -from cylc.flow.time_parser import CylcTimeParser |
| 36 | +from metomi.isodatetime.timezone import ( |
| 37 | + TimeZoneFormatMode, |
| 38 | + get_local_time_zone, |
| 39 | + get_local_time_zone_format, |
| 40 | +) |
| 41 | + |
31 | 42 | from cylc.flow.cycling import (
|
32 |
| - PointBase, IntervalBase, SequenceBase, ExclusionBase, cmp |
| 43 | + ExclusionBase, |
| 44 | + IntervalBase, |
| 45 | + PointBase, |
| 46 | + SequenceBase, |
| 47 | + cmp, |
33 | 48 | )
|
34 | 49 | from cylc.flow.exceptions import (
|
35 | 50 | CylcConfigError,
|
36 | 51 | IntervalParsingError,
|
37 | 52 | PointParsingError,
|
38 | 53 | SequenceDegenerateError,
|
39 |
| - WorkflowConfigError |
| 54 | + WorkflowConfigError, |
40 | 55 | )
|
41 |
| -from cylc.flow.wallclock import get_current_time_string |
42 | 56 | from cylc.flow.parsec.validate import IllegalValueError
|
| 57 | +from cylc.flow.time_parser import CylcTimeParser |
| 58 | +from cylc.flow.wallclock import get_current_time_string |
| 59 | + |
43 | 60 |
|
44 | 61 | if TYPE_CHECKING:
|
45 | 62 | from metomi.isodatetime.data import TimePoint
|
46 | 63 | from metomi.isodatetime.parsers import (
|
47 |
| - DurationParser, TimePointParser, TimeRecurrenceParser) |
| 64 | + DurationParser, |
| 65 | + TimePointParser, |
| 66 | + TimeRecurrenceParser, |
| 67 | + ) |
48 | 68 |
|
49 | 69 | CYCLER_TYPE_ISO8601 = "iso8601"
|
50 | 70 | CYCLER_TYPE_SORT_KEY_ISO8601 = 1
|
@@ -706,14 +726,6 @@ def ingest_time(value: str, now: Optional[str] = None) -> str:
|
706 | 726 | now = get_current_time_string()
|
707 | 727 | now_point = parser.parse(now)
|
708 | 728 |
|
709 |
| - # correct for year in 'now' if year is the only date unit specified - |
710 |
| - # https://github.com/cylc/cylc-flow/issues/4805#issuecomment-1103928604 |
711 |
| - if re.search(r"\(-\d{2}[);T]", value): |
712 |
| - now_point += Duration(years=1) |
713 |
| - # likewise correct for month if year and month are the only date units |
714 |
| - elif re.search(r"\(-\d{4}[);T]", value): |
715 |
| - now_point += Duration(months=1) |
716 |
| - |
717 | 729 | # perform whatever transformation is required
|
718 | 730 | offset = None
|
719 | 731 | if is_prev_next:
|
@@ -806,28 +818,6 @@ def prev_next(
|
806 | 818 |
|
807 | 819 | cycle_point = timepoints[my_diff.index(min(my_diff))]
|
808 | 820 |
|
809 |
| - # ensure truncated dates do not have time from 'now' included' - |
810 |
| - # https://github.com/metomi/isodatetime/issues/212 |
811 |
| - if 'T' not in value.split(')')[0]: |
812 |
| - # NOTE: Strictly speaking we shouldn't forcefully mutate TimePoints |
813 |
| - # in this way as they're meant to be immutable since |
814 |
| - # https://github.com/metomi/isodatetime/pull/165, however it |
815 |
| - # should be ok as long as the TimePoint is not used as a dict key and |
816 |
| - # we don't call any of the TimePoint's cached methods until after we've |
817 |
| - # finished mutating it. |
818 |
| - cycle_point._hour_of_day = 0 |
819 |
| - cycle_point._minute_of_hour = 0 |
820 |
| - cycle_point._second_of_minute = 0 |
821 |
| - # likewise ensure month and day from 'now' are not included |
822 |
| - # where they did not appear in the truncated datetime |
823 |
| - if re.search(r"\(-\d{2}[);T]", value): |
824 |
| - # case 1 - year only |
825 |
| - cycle_point._month_of_year = 1 |
826 |
| - cycle_point._day_of_month = 1 |
827 |
| - elif re.search(r"\(-(-\d{2}|\d{4})[;T)]", value): |
828 |
| - # case 2 - month only or year and month |
829 |
| - cycle_point._day_of_month = 1 |
830 |
| - |
831 | 821 | return cycle_point, offset
|
832 | 822 |
|
833 | 823 |
|
|
0 commit comments