Skip to content

Instantly share code, notes, and snippets.

@jcarlosroldan
Last active June 15, 2021 10:42
Show Gist options
  • Save jcarlosroldan/a0a9e385070772b208b1ef0a562f0ccc to your computer and use it in GitHub Desktop.
Save jcarlosroldan/a0a9e385070772b208b1ef0a562f0ccc to your computer and use it in GitHub Desktop.
Weekday computation
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