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.
pip install iso-week-dateVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating `IsoWeek` and `IsoWeekDate` objects from strings and `datetime.date` objects, and accessing their properties.
Always use the `iso-week-date` library's `year` property for the ISO year, or use `datetime.isocalendar()` for native `datetime` objects to get the correct ISO year, week, and weekday. Avoid relying on the Gregorian year for ISO week calculations near year boundaries.
For ISO week numbers with `datetime`, use `date.isocalendar().week` for getting the week number and `%V` with `strftime` for formatting, and ensure your input string for `strptime` aligns with ISO 8601 for week-based dates (`%G-%V-%u`). The `iso-week-date` library handles these distinctions correctly internally.
Rely on the library's methods for validation and conversion. If manually working with ISO week numbers, be aware that a year has 53 weeks if January 1st or December 31st falls on a Thursday. The `IsoWeek.weeks_in_year()` method can help determine this programmatically.
Ensure the year and week number combination is valid for the ISO week calendar. You can use `IsoWeek.weeks_in_year(year)` to check how many weeks a specific ISO year has. For example, `iso_week_date.IsoWeek.weeks_in_year(2021)` will return 52, so `IsoWeek(2021, 53)` would be invalid.
Understand that the ISO week-numbering year is distinct from the Gregorian calendar year. The library correctly implements this logic. When converting a `datetime.date` to `IsoWeekDate`, the resulting `IsoWeekDate.year` will reflect the correct ISO year, not necessarily the Gregorian year of the input date.
When using `strptime` for ISO week dates, use `%G` for the ISO year, `%V` for the ISO week number, and `%u` for the ISO weekday (1=Monday to 7=Sunday). The correct format string for 'YYYY-WNN-D' is `'%G-W%V-%u'`.
No dependency data recorded yet.