Skip to main content

A comprehensive date and period parser

Project description

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.

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

dateperiodparser-0.1.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

dateperiodparser-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dateperiodparser-0.1.2.tar.gz.

File metadata

  • Download URL: dateperiodparser-0.1.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for dateperiodparser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5d7094ba19f57646cd32e701c0e4fc8f77aa3c9e9eb7f7f5aac5eeba17d0bf1c
MD5 12ab0ff284eeb246d72a49f1f527f6fc
BLAKE2b-256 5a1a6f8a99cc48dbebe0d576c7c7f22027a74d64fef15c314097f9328374247e

See more details on using hashes here.

File details

Details for the file dateperiodparser-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dateperiodparser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 536a31bd8a679fac8ef11cf3d3918dd05fec5f61077f57b6cc4be16ed2c12800
MD5 91c8caf7f4f25d33c1d9c18abbcfd10e
BLAKE2b-256 35ceac54d49baaac971e3c44a13b9608de88803addf39ca993c2b302e0e0879b

See more details on using hashes here.

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