-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
29 lines (21 loc) · 894 Bytes
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# example_date ='C20531'
# example_output = 'June 31 2022'
import re
months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
deliminator = '-'
bluk_deliminator = '\n'
def convert_date(date, numbers):
date = re.sub(r'[\s]', '', date)
if len(date) < 4:
return
decade_hex, year_number, month_number, day_number = str(
date[0:1]), int(date[1:2]), int(date[-4:-2]), int(date[-2:])
month_string = months[month_number-1]
decade_number = 190+int(decade_hex, 16) # convert hex to int
if numbers:
return f'{month_number}{deliminator}{day_number}-{decade_number}{year_number}'
else:
return f'{month_string} {day_number} {decade_number}{year_number}'
def bulk_convert_date_new_line_deliminated(dates, numbers):
return list(map(lambda date: convert_date(date, numbers), dates.split(bluk_deliminator)))