ISO Week Date Toolkit

2.3.0 · active · verified Thu Apr 16

The `iso-week-date` library provides a toolkit for working with ISO Week date formats, specifically YYYY-WNN and YYYY-WNN-D. It offers `IsoWeek` and `IsoWeekDate` classes to manage these date formats, facilitating parsing, conversion, and operations directly, thus avoiding common pitfalls associated with converting between string, `date`, and `datetime` objects in Python. The current version is 2.3.0, and it maintains a regular release cadence as needed for updates and new features.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating `IsoWeek` and `IsoWeekDate` objects from strings and `datetime.date` objects, and accessing their properties.

from iso_week_date import IsoWeek, IsoWeekDate
from datetime import date

# Create an IsoWeek object
week = IsoWeek.from_string("2023-W10")
print(f"IsoWeek from string: {week}")

# Get the Monday of the week
monday_date = week.monday
print(f"Monday of {week}: {monday_date}")

# Create an IsoWeekDate object
isodate = IsoWeekDate.from_string("2020-W01-1") # Monday of week 1, 2020
print(f"IsoWeekDate from string: {isodate}")

# Convert a datetime.date object to IsoWeekDate
current_date = date(2023, 3, 8)
isodate_from_date = IsoWeekDate.from_date(current_date)
print(f"IsoWeekDate from {current_date}: {isodate_from_date}")

# Access properties
print(f"Year: {isodate.year}, Week: {isodate.week_number}, Day: {isodate.day}")

view raw JSON →