MCPcopy Index your code
hub / github.com/clips/pattern / _parse_date_rfc822

Function _parse_date_rfc822

pattern/web/feed/feedparser.py:3483–3523  ·  view source on GitHub ↗

Parse RFC 822 dates and times, with one minor difference: years may be 4DIGIT or 2DIGIT. http://tools.ietf.org/html/rfc822#section-5

(dt)

Source from the content-addressed store, hash-verified

3481).match
3482
3483def _parse_date_rfc822(dt):
3484 """Parse RFC 822 dates and times, with one minor
3485 difference: years may be 4DIGIT or 2DIGIT.
3486 http://tools.ietf.org/html/rfc822#section-5"""
3487 try:
3488 m = _rfc822_match(dt.lower()).groupdict(0)
3489 except AttributeError:
3490 return None
3491
3492 # Calculate a date and timestamp
3493 for k in ('year', 'day', 'hour', 'minute', 'second'):
3494 m[k] = int(m[k])
3495 m['month'] = _rfc822_months.index(m['month']) + 1
3496 # If the year is 2 digits, assume everything in the 90's is the 1990's
3497 if m['year'] < 100:
3498 m['year'] += (1900, 2000)[m['year'] < 90]
3499 stamp = datetime.datetime(*[m[i] for i in
3500 ('year', 'month', 'day', 'hour', 'minute', 'second')])
3501
3502 # Use the timezone information to calculate the difference between
3503 # the given date and timestamp and Universal Coordinated Time
3504 tzhour = 0
3505 tzmin = 0
3506 if m['tz'] and m['tz'].startswith('gmt'):
3507 # Handle GMT and GMT+hh:mm timezone syntax (the trailing
3508 # timezone info will be handled by the next `if` block)
3509 m['tz'] = ''.join(m['tz'][3:].split(':')) or 'gmt'
3510 if not m['tz']:
3511 pass
3512 elif m['tz'].startswith('+'):
3513 tzhour = int(m['tz'][1:3])
3514 tzmin = int(m['tz'][3:])
3515 elif m['tz'].startswith('-'):
3516 tzhour = int(m['tz'][1:3]) * -1
3517 tzmin = int(m['tz'][3:]) * -1
3518 else:
3519 tzhour = _rfc822_tznames[m['tz']]
3520 delta = datetime.timedelta(0, 0, 0, 0, tzmin, tzhour)
3521
3522 # Return the date and timestamp in UTC
3523 return (stamp - delta).utctimetuple()
3524registerDateHandler(_parse_date_rfc822)
3525
3526def _parse_date_asctime(dt):

Callers 1

_parse_date_greekFunction · 0.85

Calls 2

indexMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…