Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Last active June 24, 2025 04:21
Show Gist options
  • Save yeiichi/d58acd2f1e18ba77fe4cc98f9178d37e to your computer and use it in GitHub Desktop.
Save yeiichi/d58acd2f1e18ba77fe4cc98f9178d37e to your computer and use it in GitHub Desktop.
Calculate the maximum ISO week number for a given year
#!/usr/bin/env python3
from datetime import date
def get_max_iso_week(year: int) -> int:
"""
Calculates the maximum ISO week number for a given year.
ISO weeks run from Monday to Sunday. Week 1 is the week
with the year's first Thursday. The week containing December 28
is always the last ISO week of the year.
Args:
year (int): The year to check.
Returns:
int: Maximum ISO week number (52 or 53).
"""
return date(year, 12, 28).isocalendar().week
def prompt_user_for_year() -> None:
year = int(input('Year?: '))
print(get_max_iso_week(year))
if __name__ == '__main__':
prompt_user_for_year()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment