Last active
June 15, 2021 10:42
-
-
Save jcarlosroldan/a0a9e385070772b208b1ef0a562f0ccc to your computer and use it in GitHub Desktop.
Weekday computation
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
WEEK_DAYS = 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' | |
def weekday(day: int, month: int, year: int) -> str: # You'd rather operate with datetimes, but this is funnier. | |
''' Computes the day of the week using Zeller's Congruence. ''' | |
year_shift = year + year // 4 - year // 100 + year // 400 | |
return WEEK_DAYS[(5 + day + (13 * (month + 1)) // 5 + year_shift) % 7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment