iso-week-date is a toolkit to work with strings representing ISO Week date in two formats, namely:
where YYYY represents the year, W is a literal, NN represents the week number, and D represents the day of the week.
In a nutshell it provides:
IsoWeek
and IsoWeekDate
classes that implement a series of methods to work with ISO Week (Date) formats directly, avoiding the pitfalls of going back and forth between string, date and datetime python objects.Documentation | Source Code | Issue Tracker
iso-week-date is published as a Python package on pypi, and it can be installed with pip, or directly from source using git, or with a local clone:
pip (suggested):
python -m pip install iso-week-date
pip + source/git:
python -m pip install git+https://github.com/FBruzzesi/iso-week-date.git
local clone:
git clone https://github.com/FBruzzesi/iso-week-date.git
cd iso-week-date
python -m pip install .
IsoWeek
and IsoWeekDate
classes, no additional dependency is required.This is a high level overview of the features provided by the iso-week-date
package.
The IsoWeek
and IsoWeekDate
classes provide the following functionalities:
IsoWeek
(resp IsoWeekDate
) objectsint
and timedelta
typesint
, timedelta
and IsoWeek
(resp IsoWeekDate
) typesIsoWeek
(resp. IsoWeekDate
) objects__next__
method to generate the next IsoWeek
(resp. IsoWeekDate
) objectIsoWeek
unique methods/features:
days
properties that lists the dates in the given weeknth
method to get the nth day of the week as datein
operator and contains
method to check if a (iterable of) week(s), string(s) and/or date(s) is contained in the given weekweeksout
method to generate a list of weeks that are n_weeks after the given weekint
defaults to adding/subtracting weeksIsoWeekDate
unique methods/features:
day
property that returns the weekday as integerisoweek
property that returns the ISO Week of the given date (as string)daysout
method to generate a list of dates that are n_days after the given dateint
defaults to adding/subtracting dayspandas_utils
and polars_utils
modules provide functionalities to work with and move back and forth with series of ISO Week date formats.
In specific both modules implements the following functionalities:
datetime_to_isoweek
and datetime_to_isoweekdate
to convert a series of datetime objects to a series of ISO Week (date) stringsisoweek_to_datetime
and isoweekdate_to_datetime
to convert a series of ISO Week (date) strings to a series of datetime objectsis_isoweek_series
and is_isoweekdate_series
to check if a string series values match the ISO Week (date) formatTo get started with IsoWeek
and IsoWeekDate
classes please refer to the quickstart documentation section.
To check examples on how to work with pandas and polars functionalities please refer to the dataframe modules documentation section.
One of the main reason for this library to exist is the need and the flexibility to work with custom offsets, i.e. to be able to add/subtract a custom offset (as timedelta
) to the default ISO Week start and given date, and get a "shifted" week.
This feature is available both in the IsoWeek
and IsoWeekDate
classes and the dataframe functionalities.
To check an example see the working with custom offset section.
Please read the contributing guidelines in the documentation site.
The project has a MIT Licence.