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.3.tar.gz (15.3 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.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dateperiodparser-0.1.3.tar.gz
  • Upload date:
  • Size: 15.3 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.3.tar.gz
Algorithm Hash digest
SHA256 6a94590ea73bb19d8b7f75bbd8b6133bdd82e75734313ee042a71f9adbc5e3c4
MD5 bacc603bc20c574f6895871996ad081d
BLAKE2b-256 d9107580324c515af888433f20ed62fc52f5a842fe5fd2e1ba88feeab2573fcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dateperiodparser-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2125fda3fcfe54d99fd97047edc9d30b37dfbb22a963fd59cb0144fc7f838807
MD5 430d56fec782ec4bc6958fe61eb34854
BLAKE2b-256 6760269e8ce356a596c972f2fd9a9b5108b5183e935eff4a6aa0fe9ffab0aad6

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