Last active
August 31, 2022 10:03
-
-
Save blzzua/7ac6f0367b35b1423d123c9af6eeb1e9 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
def day_of_week(date): | |
""" get weekday from date (as instance 2022-12-31 iso format) """ | |
# | |
year = int(date[0:4]) | |
month = int(date[5:7]) | |
day = int(date[8:10]) | |
offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] | |
week = ['Sunday', | |
'Monday', | |
'Tuesday', | |
'Wednesday', | |
'Thursday', | |
'Friday', | |
'Saturday'] | |
after_feb = 1 | |
if month > 2: after_feb = 0 | |
aux = year - 1700 - after_feb | |
day_of_week = 5 | |
day_of_week += (aux + after_feb) * 365 | |
day_of_week += aux / 4 - aux / 100 + (aux + 100) / 400 | |
day_of_week += offset[month - 1] + (day - 1) | |
day_of_week %= 7 | |
return day_of_week |
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
def julian(y,m,d): | |
a = (14 - m)//12 | |
y += 4800 - a | |
m += 12*a - 3 | |
return (d + ((153*m + 2)//5) + 365*y + y//4 - y//100 + y//400 - 32045) % 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment