(dateString)
return time.localtime(time.mktime(tm))
Parse a variety of ISO-8601-compatible formats like 20040105
Parse a variety of ISO-8601-compatible formats like 20040105
Parse a variety of ISO - 8601 - compatible formats like 20040105
def _parse_date_iso8601(dateString):
    '''Parse a variety of ISO-8601-compatible formats like 20040105'''
    m = None
    for _iso8601_match in _iso8601_matches:
        m = _iso8601_match(dateString)
        if m: break
    if not m: return
    if m.span() == (0, 0): return
    params = m.groupdict()
    ordinal = params.get('ordinal', 0)
    if ordinal:
        ordinal = int(ordinal)
    else:
        ordinal = 0
    year = params.get('year', '--')
    if not year or year == '--':
        year = time.gmtime()[0]
    elif len(year) == 2:
        # ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993
        year = 100 * int(time.gmtime()[0] / 100) + int(year)
    else:
        year = int(year)
    month = params.get('month', '-')
    if not month or month == '-':
        # ordinals are NOT normalized by mktime, we simulate them
        # by setting month=1, day=ordinal
        if ordinal:
            month = 1
        else:
            month = time.gmtime()[1]
    month = int(month)
    day = params.get('day', 0)
    if not day:
        # see above
        if ordinal:
            day = ordinal
        elif params.get('century', 0) or \
                 params.get('year', 0) or params.get('month', 0):
            day = 1
        else:
            day = time.gmtime()[2]
    else:
        day = int(day)
    # special case of the century - is the first year of the 21st century
    # 2000 or 2001 ? The debate goes on...
    if 'century' in params.keys():
        year = (int(params['century']) - 1) * 100 + 1
    # in ISO 8601 most fields are optional
    for field in ['hour', 'minute', 'second', 'tzhour', 'tzmin']:
        if not params.get(field, None):
            params[field] = 0
    hour = int(params.get('hour', 0))
    minute = int(params.get('minute', 0))
    second = int(params.get('second', 0))
    # weekday is normalized by mktime(), we can ignore it
    weekday = 0
    # daylight savings is complex, but not needed for feedparser's purposes
    # as time zones, if specified, include mention of whether it is active
    # (e.g. PST vs. PDT, CET). Using -1 is implementation-dependent and
    # and most implementations have DST bugs
    daylight_savings_flag = 0
    tm = [year, month, day, hour, minute, second, weekday,
          ordinal, daylight_savings_flag]
    # ISO 8601 time zone adjustments
    tz = params.get('tz')
    if tz and tz != 'Z':
        if tz[0] == '-':
            tm[3] += int(params.get('tzhour', 0))
            tm[4] += int(params.get('tzmin', 0))
        elif tz[0] == '+':
            tm[3] -= int(params.get('tzhour', 0))
            tm[4] -= int(params.get('tzmin', 0))
        else:
            return None
    # Python's time.mktime() is a wrapper around the ANSI C mktime(3c)
    # which is guaranteed to normalize d/m/y/h/m/s.
    # Many implementations have bugs, but we'll pretend they don't.
    return time.localtime(time.mktime(tm))
def _parse_date_iso8601 ( dateString ) : m = None for _iso8601_match in _iso8601_matches : m = _iso8601_match ( dateString ) if m : break if not m : return if m . span ( ) == ( 0 , 0 ) : return params = m . groupdict ( ) ordinal = params . get ( 'ordinal' , 0 ) if ordinal : ordinal = int ( ordinal ) else : ordinal = 0 year = params . get ( 'year' , '--' ) if not year or year == '--' : year = time . gmtime ( ) [ 0 ] elif len ( year ) == 2 : # ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993 year = 100 * int ( time . gmtime ( ) [ 0 ] / 100 ) + int ( year ) else : year = int ( year ) month = params . get ( 'month' , '-' ) if not month or month == '-' : # ordinals are NOT normalized by mktime, we simulate them # by setting month=1, day=ordinal if ordinal : month = 1 else : month = time . gmtime ( ) [ 1 ] month = int ( month ) day = params . get ( 'day' , 0 ) if not day : # see above if ordinal : day = ordinal elif params . get ( 'century' , 0 ) or params . get ( 'year' , 0 ) or params . get ( 'month' , 0 ) : day = 1 else : day = time . gmtime ( ) [ 2 ] else : day = int ( day ) # special case of the century - is the first year of the 21st century # 2000 or 2001 ? The debate goes on... if 'century' in params . keys ( ) : year = ( int ( params [ 'century' ] ) - 1 ) * 100 + 1 # in ISO 8601 most fields are optional for field in [ 'hour' , 'minute' , 'second' , 'tzhour' , 'tzmin' ] : if not params . get ( field , None ) : params [ field ] = 0 hour = int ( params . get ( 'hour' , 0 ) ) minute = int ( params . get ( 'minute' , 0 ) ) second = int ( params . get ( 'second' , 0 ) ) # weekday is normalized by mktime(), we can ignore it weekday = 0 # daylight savings is complex, but not needed for feedparser's purposes # as time zones, if specified, include mention of whether it is active # (e.g. PST vs. PDT, CET). Using -1 is implementation-dependent and # and most implementations have DST bugs daylight_savings_flag = 0 tm = [ year , month , day , hour , minute , second , weekday , ordinal , daylight_savings_flag ] # ISO 8601 time zone adjustments tz = params . get ( 'tz' ) if tz and tz != 'Z' : if tz [ 0 ] == '-' : tm [ 3 ] += int ( params . get ( 'tzhour' , 0 ) ) tm [ 4 ] += int ( params . get ( 'tzmin' , 0 ) ) elif tz [ 0 ] == '+' : tm [ 3 ] -= int ( params . get ( 'tzhour' , 0 ) ) tm [ 4 ] -= int ( params . get ( 'tzmin' , 0 ) ) else : return None # Python's time.mktime() is a wrapper around the ANSI C mktime(3c) # which is guaranteed to normalize d/m/y/h/m/s. # Many implementations have bugs, but we'll pretend they don't. return time . localtime ( time . mktime ( tm ) )