date-ranges
A DateRange
type and related utility functions.
Quickstart
Install from pip:
pip install date-ranges
Import and create an instance:
from datetime import date
from date_ranges import DateRange
my_date_range = DateRange(start=date(2023, 5, 10), end=date(2023, 11, 3))
Usage
from datetime import date
from date_ranges import DateRange, MAX_DATE
dr = DateRange(date(2023, 11, 1))
date(2023, 11, 22) in dr
empty = DateRange.empty()
bool(empty)
for d in DateRange(date(2023, 1, 1), date(2023, 1, 3)):
print(d)
dr = DateRange.from_string('20230101-20230103')
repr(dr)
dr = DateRange.from_string('20231031')
repr(dr)
dr = DateRange.from_string('202305')
repr(dr)
dr = DateRange.from_string('202305-202311')
repr(dr)
dr = DateRange(date(2023, 1, 1), date(2023, 1, 3))
dr
print(f'{dr:H}')
dr = DateRange.from_string('202305')
f'{dr:H}'
f'{dr:C}'
dr
Development
For those developing or maintaining the date-ranges
package itself,
be sure to install it with the [dev]
option to pull in packages
used when developing.
pip install --editable .[dev]
When developing, this package uses pre-commit
. After the initial
clone of the repository, you will need to set up pre-commit with:
# in the top level of the checked-out repository:
pre-commit install
Changelog
0.0.1 released 2023-11-03