-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculate_day.py
38 lines (34 loc) · 1.28 KB
/
calculate_day.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
30
31
32
33
34
35
36
37
38
from data_dict import century_dict, year_dict, month_dict
# Check website given in README.md for explanation about formula and values below
def calculate_day(day, month, year):
# Transform year to known year number code
year_code = str(year)[-2:]
century_code = int(str(year)[:2]) % 4
print(century_code)
while True:
if int(year_code) <= 27:
year_final = int(year_dict[year_code])
break
elif 27 < int(year_code) <= 55:
year_code = str(int(year_code) - 28)
year_final = int(year_dict[year_code])
break
elif 55 < int(year_code) <= 83:
year_code = str(int(year_code) - 56)
year_final = int(year_dict[year_code])
break
elif 83 < int(year_code) <= 99:
year_code = str(int(year_code) - 84)
year_final = int(year_dict[year_code])
break
# Account for Leap years
if int(year_code) % 4 == 0:
if int(month) <= 2:
month_final = int(month_dict[month]) - 1
else:
month_final = int(month_dict[month])
else:
month_final = int(month_dict[month])
# Find day of week
day_calc = (month_final + year_final + int(day) + int(century_dict[century_code])) % 7
return day_calc