gordias.util.time_string.parse_time_range#

gordias.util.time_string.parse_time_range(time_range: str, end_inclusive: bool = False) TimeRange#

Parse a time range string given in CMIP/CORDEX-like format.

Parameters:
  • time_range (str) –

    A time range given in CMIP/CORDEX-like format, as described in CMIP6 Global Attributes, DRS, Filenames, Directory Structure, and CV’s:

    The <time_range> is a string generated consistent with the
    following:
    
    If frequency = "fx" then
        <time_range>=""
    else
        <time_range> = N1-N2 where N1 and N2 are integers of the form
        "yyyy[MM[dd[hh[mm[ss]]]]][<suffix>]" (expressed as a string,
        where "yyyy", "MM", "dd", "hh", "mm", and "ss" are integer
        year, month, day, hour, minute, and second, respectively)
    endif
    
    where <suffix> is defined as follows:
    
    if the variable identified by variable_id has a time dimension with
    a "climatology" attribute then
        suffix = "-clim"
    else
        suffix = ""
    endif
    
    and where the precision of the time_range strings is determined by
    the "frequency" global attribute as specified in Table 2.
    

  • end_inclusive (bool, optional) – If True, a delta will be added to end time, to guarantee that the end time in the given string is within the returned time range. The size of the delta is determined by the resolution of the times in the given time string. Default is False.

Returns:

Extracted TimeRange object.

Return type:

TimeRange