dateperiodparser
A python package for parsing natural language periods and dates into standardized date ranges. It is designed to handle a wide variety of date and period formats, including ISO dates, school years, quarters, seasons, multi-year ranges, relative dates, and much more, across varying languages (English, Dutch, etc.).
Installation
You can install the package via pip:
pip install dateperiodparser
Quick Start
from dateperiodparser import DatePeriodParser
parser = DatePeriodParser()
# Parse a specific phrase
results = parser.parse("school year 2025 - 2026")
for r in results:
# r.start and r.end are datetime objects
print(f"Start: {r.start.date()} -> End: {r.end.date()}")
print(f"Matched by: {r.pattern}")
Features and Examples
The DatePeriodParser utilizes a series of prioritized matchers to detect common and custom date formats. When a text string is parsed, it evaluates the text and attempts to return a list of DateResult components representing the extracted (start, end) tuple pairs.
1. Simple Dates & ISO
The parser naturally handles basic dates, including ISO-8601 formatting, short date text, and separated days representing specific matching instances.
parser.parse("2024-01-15T10:30:00Z")
# Output: 2024-01-15 -> 2024-01-15
parser.parse("March 2, 3, and 4, 2025")
# Output:
# 2025-03-02 -> 2025-03-02
# 2025-03-03 -> 2025-03-03
# 2025-03-04 -> 2025-03-04
2. Academic and Financial Periods
dateperiodparser efficiently identifies quarters, semesters (half-years), and academic school years spanning multiple calendar years.
parser.parse("academiejaar 2024-2025") # Dutch: Academic year 2024-2025
# Output: 2024-09-01 -> 2025-06-30
parser.parse("Q3 2024")
# Output: 2024-07-01 -> 2024-09-30
parser.parse("second half 2024")
# Output: 2024-07-01 -> 2024-12-31
3. Date Ranges & Multi-year sequences
The parser is helpful for extracting bounds from continuous periods or enumerating multi-year intervals specified in natural text.
parser.parse("2022 to 2025")
# Output: 2022-01-01 -> 2025-12-31
parser.parse("2021, 2022, and 2023")
# Output:
# 2021-01-01 -> 2021-12-31
# 2022-01-01 -> 2022-12-31
# 2023-01-01 -> 2023-12-31
parser.parse("from 7 February 2022 to 6 March 2022")
# Output: 2022-02-07 -> 2022-03-06
4. Seasons
The package contains dedicated handling for periods expressed as a "season".
parser.parse("spring 2022")
# Output: 2022-03-01 -> 2022-05-31
parser.parse("zomer 2024") # Dutch: summer 2024
# Output: 2024-06-01 -> 2024-08-31
Edge Cases and Fallbacks
If text represents single values, generic dates, or formats that are heavily intermixed with language variations, it drops back to general parsing mechanisms (including an internal dependency on the dateparser logic) to find the closest matching span of time based strictly on textual boundaries.
Metadata
Release files for dateperiodparser 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dateperiodparser-0.1.3.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dateperiodparser-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.8 kB
Release files / dateperiodparser-0.1.3.tar.gz
| Download URL | dateperiodparser-0.1.3.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a94590ea73bb19d8b7f75bbd8b6133bdd82e75734313ee042a71f9adbc5e3c4
|
|
BLAKE2b-256 checksum How to use checksums |
d9107580324c515af888433f20ed62fc52f5a842fe5fd2e1ba88feeab2573fcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / dateperiodparser-0.1.3-py3-none-any.whl
| Download URL | dateperiodparser-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2125fda3fcfe54d99fd97047edc9d30b37dfbb22a963fd59cb0144fc7f838807
|
|
BLAKE2b-256 checksum How to use checksums |
6760269e8ce356a596c972f2fd9a9b5108b5183e935eff4a6aa0fe9ffab0aad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|