Toolkit to work with str representing ISO Week date format
Project description
iso-week-date
iso-week-date is a toolkit to work with strings representing ISO Week date in two formats, namely:
- Week format YYYY-WNN (corresponding to the date format %Y-W%V)
- Week date format YYYY-WNN-D (corresponding to the date format %Y-W%V-%u)
In a nutshell it provides:
IsoWeek
andIsoWeekDate
classes implementing a series of methods to work with ISO Week date formats and avoiding the pitfalls of going back and forth between string, date and datetime python objects.- pandas and polars functionalities to work with series of ISO Week dates.
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
andIsoWeekDate
classes, no additional dependency is required. - pandas and polars functionalities require the installation of the respective libraries.
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
(respIsoWeekDate
) objects - Addition with
int
andtimedelta
types - Subtraction with
int
,timedelta
andIsoWeek
(respIsoWeekDate
) types - Range between two
IsoWeek
(resp.IsoWeekDate
) objects __next__
method to generate the nextIsoWeek
(resp.IsoWeekDate
) object
IsoWeek
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 andcontains
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 week- Addition and subtraction with
int
defaults to adding/subtracting weeks
IsoWeekDate
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 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 dates in YYYY-WNN format.
In specific both modules implements the following:
datetime_to_isoweek
to convert a series of datetime objects to a series of Iso Week stringsisoweek_to_datetime
to convert a series of Iso Week strings to a series of datetime objectsis_isoweek_series
to check if a string series values match the ISO Week formatis_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 of 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 present 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file iso-week-date-0.0.2.tar.gz
.
File metadata
- Download URL: iso-week-date-0.0.2.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a419f744a161be8ba64ae59d94fee09baf9ce47b8d834bd521520147bab042a9 |
|
MD5 | a0e6475b54149895c390548ed0eb0947 |
|
BLAKE2b-256 | f4258ea783576ed4f67b08eb6bbd49df95d27c781a0994c62b8eb2b8c7cccac5 |
File details
Details for the file iso_week_date-0.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: iso_week_date-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e83ffbef2f496ad4aec7162f736ed574461dc83b73751f62f3eee3577ae76dc8 |
|
MD5 | 5aef00d1ed07286a01dbd8d8bece45b6 |
|
BLAKE2b-256 | e92fcee505239541f66d14572aef71fa3ff73601afebf00f5d1288fb5aaa459d |