def set_calendar_mode(calendar_mode=None): """Set calendar mode for subsequent operations. Raise KeyError if calendar_mode is invalid. """ if not calendar_mode: calendar_mode = os.getenv("ROSE_CYCLING_MODE") if calendar_mode and calendar_mode in Calendar.MODES: Calendar.default().set_mode(calendar_mode)
def init(num_expanded_year_digits=0, custom_dump_format=None, time_zone=None, assume_utc=False, cycling_mode=None): """Initialise workflow-setup-specific information.""" if cycling_mode in Calendar.default().MODES: Calendar.default().set_mode(cycling_mode) if time_zone is None: if assume_utc: time_zone = "Z" time_zone_hours_minutes = (0, 0) else: time_zone = get_local_time_zone_format(TimeZoneFormatMode.reduced) time_zone_hours_minutes = get_local_time_zone() else: time_zone_hours_minutes = TimePointDumper().get_time_zone(time_zone) WorkflowSpecifics.ASSUMED_TIME_ZONE = time_zone_hours_minutes WorkflowSpecifics.NUM_EXPANDED_YEAR_DIGITS = num_expanded_year_digits if custom_dump_format is None: if num_expanded_year_digits > 0: WorkflowSpecifics.DUMP_FORMAT = ( EXPANDED_DATE_TIME_FORMAT + time_zone ) else: WorkflowSpecifics.DUMP_FORMAT = DATE_TIME_FORMAT + time_zone else: WorkflowSpecifics.DUMP_FORMAT = custom_dump_format if "+X" not in custom_dump_format and num_expanded_year_digits: raise IllegalValueError( 'cycle point format', ('cylc', 'cycle point format'), WorkflowSpecifics.DUMP_FORMAT ) WorkflowSpecifics.iso8601_parsers = CylcTimeParser.initiate_parsers( dump_format=WorkflowSpecifics.DUMP_FORMAT, num_expanded_year_digits=num_expanded_year_digits, assumed_time_zone=WorkflowSpecifics.ASSUMED_TIME_ZONE ) (WorkflowSpecifics.point_parser, WorkflowSpecifics.interval_parser, WorkflowSpecifics.recurrence_parser) = WorkflowSpecifics.iso8601_parsers WorkflowSpecifics.abbrev_util = CylcTimeParser( None, None, WorkflowSpecifics.iso8601_parsers )
def coerce_interval(self, value, keys): """Coerce an ISO 8601 interval (or number: back-comp) into seconds.""" value = self.strip_and_unquote(keys, value) if not value: # Allow explicit empty values. return None try: interval = DurationParser().parse(value) except ValueError: raise IllegalValueError("ISO 8601 interval", keys, value) days, seconds = interval.get_days_and_seconds() return DurationFloat( days * Calendar.default().SECONDS_IN_DAY + seconds)
def coerce_interval(cls, value, keys): """Coerce an ISO 8601 interval into seconds. Examples: >>> CylcConfigValidator.coerce_interval('PT1H', None) 3600.0 """ value = cls.strip_and_unquote(keys, value) if not value: # Allow explicit empty values. return None try: interval = DurationParser().parse(value) except ValueError: raise IllegalValueError("ISO 8601 interval", keys, value) days, seconds = interval.get_days_and_seconds() return DurationFloat( days * Calendar.default().SECONDS_IN_DAY + seconds)
def get_calendar_mode(): """Get current calendar mode.""" return Calendar.default().mode