ISO Week Objects

1.3.3 · maintenance · verified Sun Apr 12

The `isoweek` module provides the `Week` class, which represents specific weeks spanning Monday to Sunday, adhering to the ISO 8601 week definition. It correctly handles the 52 or 53 numbered weeks in a year, where Week 1 is the first week with four or more days in January. The library is lightweight and immutable, offering an interface similar to `datetime.date` objects. The current version is 1.3.3, and the project appears to be in maintenance mode with infrequent updates, with its last PyPI release in 2017 and GitHub activity noted as 5 years ago.

Warnings

Install

Imports

Quickstart

Demonstrates creating Week objects, retrieving days, getting the current week, finding the week for a specific date, and checking date containment within a week.

from isoweek import Week
from datetime import date

# Create a Week object
w = Week(2023, 10) # 10th week of 2023
print(f"Week: {w}")

# Get days of the week
print(f"Monday of week {w}: {w.monday()}")
print(f"Sunday of week {w}: {w.sunday()}")
print(f"All days: {w.days()}")

# Get current week
current_week = Week.thisweek()
print(f"Current ISO week: {current_week}")

# Get week containing a specific date
some_date = date(2023, 3, 8)
week_of_date = Week.withdate(some_date)
print(f"Week of {some_date}: {week_of_date}")

# Check if a date is in a week
print(f"Is {some_date} in {w}? {w.contains(some_date)}")
print(f"Is {some_date} in {week_of_date}? {week_of_date.contains(some_date)}")

view raw JSON →