ocw/utils.py
def parse_time_base(time_format):
    ''' Parse time base object from the time units string.

    :param time_format: The time data units string from the dataset
        being processed. The string should be of the format
        '<units> since <base time date>'
    :type time_format: :mod:`string`

    :returns: The base time as a datetime object.

    :raises ValueError: When the base time string couldn't be parsed from the
        units time_format string or if the date string didn't match any of the
        expected formats.
    '''
    base_time_string = parse_base_time_string(time_format)

    time_format = time_format.strip()

    possible_time_formats = [
        '%Y:%m:%d %H:%M:%S', '%Y-%m-%d %H-%M-%S', '%Y/%m/%d %H/%M/%S',
        '%Y-%m-%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', '%Y%m%d %H:%M:%S',
        '%Y%m%d%H%M%S', '%Y-%m-%d-%H-%M-%S', '%Y/%m/%d/%H/%M/%S',
        '%Y:%m:%d:%H:%M:%S', '%Y-%m-%d-%H:%M:%S', '%Y-%m-%d %H:%M:%S',
        '%Y/%m/%d%H:%M:%S', '%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
        '%Y:%m:%d %H:%M', '%Y%m%d %H:%M', '%Y-%m-%d', '%Y/%m/%d',
        '%Y:%m:%d', '%Y%m%d', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H',
        '%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%SZ'
    ]

    # Attempt to match the base time string with a possible format parsing
    # string.
    for time_format in possible_time_formats:
        try:
            stripped_time = dt.datetime.strptime(base_time_string, time_format)
            break
        except ValueError:
            # This exception means that the time format attempted was
            # incorrect. No need to report or raise this,
            # simply try the next one!
            pass
    # If we got through the entire loop without a break, we couldn't parse the
    # date string with our known formats.
    else:
        cur_frame = sys._getframe().f_code
        err = "{}.{}: Unable to parse valid date from {}".format(
            cur_frame.co_filename,
            cur_frame.co_name,
            base_time_string
        )

        raise ValueError(err)

    return stripped_time
 Parse time base object from the time units string.

    :param time_format: The time data units string from the dataset
        being processed. The string should be of the format
        '<units> since <base time date>'
    :type time_format: :mod:`string`

    :returns: The base time as a datetime object.

    :raises ValueError: When the base time string couldn't be parsed from the
        units time_format string or if the date string didn't match any of the
        expected formats.
    
Parse time base object from the time units string.
Parse time base object from the time units string .
def parse_time_base(time_format):
    base_time_string = parse_base_time_string(time_format)
    time_format = time_format.strip()
    possible_time_formats = [
        '%Y:%m:%d %H:%M:%S', '%Y-%m-%d %H-%M-%S', '%Y/%m/%d %H/%M/%S',
        '%Y-%m-%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', '%Y%m%d %H:%M:%S',
        '%Y%m%d%H%M%S', '%Y-%m-%d-%H-%M-%S', '%Y/%m/%d/%H/%M/%S',
        '%Y:%m:%d:%H:%M:%S', '%Y-%m-%d-%H:%M:%S', '%Y-%m-%d %H:%M:%S',
        '%Y/%m/%d%H:%M:%S', '%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
        '%Y:%m:%d %H:%M', '%Y%m%d %H:%M', '%Y-%m-%d', '%Y/%m/%d',
        '%Y:%m:%d', '%Y%m%d', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H',
        '%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%SZ'
    ]
    for time_format in possible_time_formats:
        try:
            stripped_time = dt.datetime.strptime(base_time_string, time_format)
            break
        except ValueError:
            pass
    else:
        cur_frame = sys._getframe().f_code
        err = "{}.{}: Unable to parse valid date from {}".format(
            cur_frame.co_filename,
            cur_frame.co_name,
            base_time_string
        )
        raise ValueError(err)
    return stripped_time
def parse_time_base ( time_format ) : base_time_string = parse_base_time_string ( time_format ) time_format = time_format . strip ( ) possible_time_formats = [ '%Y:%m:%d %H:%M:%S' , '%Y-%m-%d %H-%M-%S' , '%Y/%m/%d %H/%M/%S' , '%Y-%m-%d %H:%M:%S' , '%Y/%m/%d %H:%M:%S' , '%Y%m%d %H:%M:%S' , '%Y%m%d%H%M%S' , '%Y-%m-%d-%H-%M-%S' , '%Y/%m/%d/%H/%M/%S' , '%Y:%m:%d:%H:%M:%S' , '%Y-%m-%d-%H:%M:%S' , '%Y-%m-%d %H:%M:%S' , '%Y/%m/%d%H:%M:%S' , '%Y-%m-%d %H:%M' , '%Y/%m/%d %H:%M' , '%Y:%m:%d %H:%M' , '%Y%m%d %H:%M' , '%Y-%m-%d' , '%Y/%m/%d' , '%Y:%m:%d' , '%Y%m%d' , '%Y-%m-%d %H:%M:%S.%f' , '%Y-%m-%d %H' , '%Y-%m-%dT%H:%M:%S' , '%Y-%m-%dT%H:%M:%SZ' ] for time_format in possible_time_formats : try : stripped_time = dt . datetime . strptime ( base_time_string , time_format ) break except ValueError : pass else : cur_frame = sys . _getframe ( ) . f_code err = "{}.{}: Unable to parse valid date from {}" . format ( cur_frame . co_filename , cur_frame . co_name , base_time_string ) raise ValueError ( err ) return stripped_time
Parse time base object from the time units string.
Parse time base object from the time units string .
''' Parse time base object from the time units string.

    :param time_format: The time data units string from the dataset
        being processed. The string should be of the format
        '<units> since <base time date>'
    :type time_format: :mod:`string`

    :returns: The base time as a datetime object.

    :raises ValueError: When the base time string couldn't be parsed from the
        units time_format string or if the date string didn't match any of the
        expected formats.
    ''' # Attempt to match the base time string with a possible format parsing # string. # This exception means that the time format attempted was # incorrect. No need to report or raise this, # simply try the next one! # If we got through the entire loop without a break, we couldn't parse the # date string with our known formats.
The base time as a datetime object.
The base time as a datetime object .
When the base time string couldn't be parsed from the
units time_format string or if the date string didn't match any of the
expected formats.
When the base time string couldn ' t be parsed from the units time_format string or if the date string didn ' t match any of the expected formats .
ValueError
time_format
The time data units string from the dataset
being processed. The string should be of the format
' since '
The time data units string from the dataset being processed . The string should be of the format ' since '