Last active
August 29, 2015 14:27
-
-
Save ibrechin/2409c4c3f399cb4a1358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
from datetime import datetime | |
p = re.compile('([A-Za-z][0-9]{4}[A-Za-z]{2}).*?([0-9]{1,2}).*?([0-9]{1,2}).*?([0-9]{2,4})') | |
def parse_ref(ref): | |
m = p.match(ref) | |
if m: | |
date_str = '%s/%s/%s' % (m.group(2), m.group(3), m.group(4)) | |
try: | |
dob = datetime.strptime(date_str, '%d/%m/%Y') | |
except ValueError: | |
dob = datetime.strptime(date_str, '%d/%m/%y') | |
# set correct century for 2 digit year | |
if dob.year > datetime.today().year - 10: | |
dob = dob.replace(year=dob.year-100) | |
print('%s, %s' % (m.group(1), dob.strftime('%Y-%m-%d'))) | |
parse_ref('a1450ae20071976') | |
parse_ref('A1450AE20/07/1976') | |
parse_ref('A1450AE 01-07-76') | |
parse_ref('A1450AE 1776') | |
parse_ref('A1450AE:01 07 76') | |
if len(sys.argv) > 1: | |
parse_ref(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment