Skip to content

Instantly share code, notes, and snippets.

@fffonion
Created June 23, 2020 08:15
Show Gist options
  • Save fffonion/88568d35777866a860b61e7961d1dc45 to your computer and use it in GitHub Desktop.
Save fffonion/88568d35777866a860b61e7961d1dc45 to your computer and use it in GitHub Desktop.
rfc822
import re
import time
def rfc822(s):
_ = re.findall("[A-z][a-z]+,\s*([^\+G]+)(?:$|\s([\+\-]*)(\d+|GMT))", s)
if not s:
print("%s is not RFC822 Date" % s)
return 0
dt, sgn, tz = _[0]
if tz == "GMT":
tz = 0
return time.mktime(time.strptime(dt, "%d %b %Y %H:%M:%S")) - (-1 if sgn == '-' else 1) * int(tz) * 36 # 0800 => 800 / 100 * 3600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment