Skip to main content

Toolkit to work with str representing ISO Week date format

Project description

ISO Week Date

PyPI version license-shield pypi-versions Trusted publishing Ruff coverage interrogate-shield PYPI - Types

iso-week-date is a toolkit to work with strings representing ISO Week date in two formats, namely:

  • Week format YYYY-WNN (date format %Y-W%V)
  • Week date format YYYY-WNN-D (date format %Y-W%V-%u)

where YYYY represents the year, W is a string literal, NN represents the week number, and D represents the day of the week.

In a nutshell it provides:


Documentation | Source Code | Issue Tracker


Installation

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 .
    

Dependencies

  • To work with IsoWeek and IsoWeekDate classes, no additional dependency is required.
  • pandas and polars functionalities require the installation of the respective libraries.
  • pydantic integration requires pydantic>=2.40.

Getting Started

Available features

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:

  • Parsing from string, date and datetime objects.
  • Conversion to string, date and datetime objects.
  • Comparison operations between IsoWeek (resp IsoWeekDate) objects.
  • Addition with int types.
  • Subtraction with int and IsoWeek (resp IsoWeekDate) types.
  • Range between two IsoWeek (resp. IsoWeekDate) objects.

IsoWeek unique methods/features:

  • days properties that lists the dates in the given week
  • nth method to get the nth day of the week as date
  • in operator and contains method to check if a (iterable of) week(s), string(s) and/or date(s) is contained in the given week
  • weeksout method to generate a list of weeks that are n_weeks after the given week
  • Addition and subtraction with int defaults to adding/subtracting weeks

IsoWeekDate unique methods/features:

  • day property that returns the weekday as integer
  • isoweek 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 date
  • Addition and subtraction with int defaults to adding/subtracting days

pandas_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) strings
  • isoweek_to_datetime and isoweekdate_to_datetime to convert a series of ISO Week (date) strings to a series of datetime objects
  • is_isoweek_series and is_isoweekdate_series to check if a string series values match the ISO Week (date) format

Quickstart

To 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.

Custom offset

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.

Contributing

Please read the contributing guidelines in the documentation site.

License

The project has a MIT Licence.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iso_week_date-2.2.2.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iso_week_date-2.2.2-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file iso_week_date-2.2.2.tar.gz.

File metadata

  • Download URL: iso_week_date-2.2.2.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iso_week_date-2.2.2.tar.gz
Algorithm Hash digest
SHA256 70bac02294cb991cc0a7b463b630f1a296a06efcca2d3517ae00d22795873aa1
MD5 d6f57e2823fde416dfcb335984788718
BLAKE2b-256 9da7dc38b19f8c78c8ccdaa9b33cdb207ddd6392cfaaf205ded370b04579023b

See more details on using hashes here.

Provenance

The following attestation bundles were made for iso_week_date-2.2.2.tar.gz:

Publisher: release.yaml on FBruzzesi/iso-week-date

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file iso_week_date-2.2.2-py3-none-any.whl.

File metadata

  • Download URL: iso_week_date-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iso_week_date-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7503a0169a852d9611f55912afbd9789b5e3c84392bcc5acf952ceada1afb853
MD5 7b4290f7865b6783da26bfaedc486771
BLAKE2b-256 6fb2c3d6a1d8deea2a5ef5bf6ebb188c85fe09c83a92ae2e98f35eb467f8d7d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for iso_week_date-2.2.2-py3-none-any.whl:

Publisher: release.yaml on FBruzzesi/iso-week-date

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page