dateling provides a normalized formal language and grammar for handling relative time expressions. It includes a DSL (domain-specific language) to represent time anchors, offsets, and modifiers, along with a robust parser and resolver to evaluate these expressions into concrete dates. The name 'dateling' comes from combining 'date' and 'handling', reflecting its purpose of handling complex date computations
Project description
dateling
๐ฐ dateling โ A Time Expression DSL and parser for deterministic date calculations.
dateling provides a normalized formal language (DSL) to represent and resolve date calculations using structured expressions.
Instead of parsing ambiguous natural language, it offers a precise syntax to express relative and absolute dates, compute date ranges, and perform robust date arithmetic.
The name dateling comes from combining date and handling.
๐ Why dateling?
Most existing packages like dateparser or parsedatetime try to interpret free-text natural language into dates.
In contrast, dateling takes a strict, declarative, and composable approach, offering:
- โ Predictable & reproducible date evaluation
- โ Fully composable date expressions
- โ Explicit syntax without ambiguity
- โ Ideal for any system requiring controlled time range calculations
- โ No natural language processing โ purely deterministic time logic
๐ฆ What's New in v1.2 & v1.3
โ v1.2 Updates:
- Added
${}support as an alternative bracket style to{}. - Added new anchor keywords:
first_date_of_this_monthโ resolves to the first day of the current month.monday_of_this_weekโ resolves to the Monday of the current week.
โ v1.3 Updates:
- Added
month=nearest_monthmodifier.- Similar to
year=nearest_year, but applies nearest-month logic. - If the resolved date falls into the future, fallback to previous month (and adjust year if necessary).
- Similar to
- Further improved composability of partial expressions (ex: "11์ผ์ ์ฃผ๊ฐ ์๋ ค์ค" โ
{today | year=nearest_year, month=nearest_month, day=11}).
โ v1.3.1 Updates:
- Added new anchor keywords:
first_date_of_this_yearโ resolves to the first day of the current year.
โ v1.3.2 Updates:
- Supports for blank after (+/-) sign:
- now supports for
{today + 1d}๋ค! ๊ธฐ์กด README ํฌ๋งท์ ๊ทธ๋๋ก ์ ์งํ๋ฉด์ **๋ณ๊ฒฝ๋ ์ง์ ๊ธฐ๋ฅ(week offset, full weekday anchors ๋ฑ)**์ด ๋ฐ์๋ DSL ๋ฌธ์ ํ์ ์์๋ก ๋ง์ถฐ๋๋ฆด๊ฒ์.
- now supports for
โ v1.4 Updates:
-
Added support for week (
w) offset unit:- Now supports
{today -1w},{monday +2w}, etc.
- Now supports
-
Added full weekday anchors:
- Now supports
{monday},{tuesday}, ...,{sunday}for this week. - Also supports
{monday_of_this_week},{last_friday},{wednesday_of_last_week}, etc.
- Now supports
-
Allows blank after
+/-sign (e.g.{today + 1w}).
๐ DSL Syntax
The general expression format is:
{anchor [+/- offset] | [modifiers]}
Anchors:
today(system reference date)first_date_of_this_yearfirst_date_of_this_monthmonday_of_this_week,tuesday_of_this_week, ...,sunday_of_this_weekmonday,tuesday, ...,sunday(this week)last_monday, ...,last_sunday(previous week)monday_of_last_week, ...,sunday_of_last_weekYYYYMMDD(e.g.20250101)YYYY-MM-DD(e.g.2025-01-01){year=YYYY, month=MM, day=DD}(absolute date)
Offsets:
- Days:
+Nd,-Nd - Weeks:
+Nw,-Nwโ NEW - Months:
+Nm,-Nm - Years:
+Ny,-Ny - (Spaces after
+/-are allowed, e.g.{today + 1w})
Modifiers:
year_startโ resolves to start of yearyear_endโ resolves to end of yearyear=nearest_yearโ use anchor year, fallback to previous year if resulting date is in the futureyear=YYYYโ explicitly set yearmonth=nearest_monthโ anchor month, fallback to previous month if resulting date is in the futuremonth=MMโ override monthday=DDโ override day
๐ Examples
| DSL Expression | Meaning | |
|---|---|---|
{today} |
today's date | |
${today} |
today's date | |
{today -1d} |
1 day before today | |
{today -1w} |
1 week before today | |
{today + 2w} |
2 weeks after today | |
{monday} |
Monday of this week | |
{sunday_of_this_week} |
Sunday of this week | |
{last_friday} |
Friday of last week | |
{tuesday_of_last_week} |
Tuesday of last week | |
{today -1y | year_start} |
start of year, 1 year ago | |
{2025-01-01 +30y | year_end} |
year-end of 30 years after Jan 1, 2025 | |
{today | year=nearest_year, month=03, day=10} |
March 10 of anchor year (or previous year if future) | |
{year=2023, month=05, day=15} |
absolute date | |
2025-01-01 |
absolute date | |
20250101 |
absolute date |
๐ฌ Evaluation Example (Reference date: 2025-07-22)
| DSL | Output | |
|---|---|---|
{today} |
2025-07-22 | |
{today -1d} |
2025-07-21 | |
{today -1w} |
2025-07-15 | |
{today +2w} |
2025-08-05 | |
{monday} |
2025-07-21 | |
{last_sunday} |
2025-07-20 | |
{tuesday_of_last_week} |
2025-07-15 | |
{today -365d|year=nearest_year} |
2024-07-22 | |
{today -3y} |
2022-07-22 | |
{today | year_start} |
2025-01-01 | |
{today | year_end} |
2025-12-31 | |
{today -1y | year_start} |
2024-01-01 | |
{today -1y | year_end} |
2024-12-31 | |
{today | year=nearest_year, month=06, day=10} |
2025-06-10 | |
{today -1y | year=nearest_year, month=03, day=10} |
2024-03-10 | |
{today | year=2024, month=06, day=10} |
2024-06-10 | |
{year=2022, month=05, day=15} |
2022-05-15 | |
2025-01-01 |
2025-01-01 | |
20250101 |
2025-01-01 | |
{1000-01-01 +30y| year_end} |
1030-12-31 | |
{today -36m} |
2022-07-22 |
ํ์์ ๋ฐ๋ผ ์์ ๋ ์กฐ์ ํ๊ฑฐ๋, example ๋ ์ถ๊ฐ ๊ฐ๋ฅํฉ๋๋ค!
โ Usage
from dateling import DatelingResolver
resolver = DatelingResolver()
date = resolver.resolve("{today -1y | year_start}")
print(date)
You may also set a fixed reference date:
resolver = DatelingResolver(reference_date="2025-06-11")
date = resolver.resolve("{today -3y | year_end}")
print(date)
๐ฆ Installation
pip install dateling
(Once released to PyPI)
๐ง Design Philosophy
- ๐งฎ Formal expression language for time calculation
- ๐ Fully deterministic, reproducible, and testable
- ๐ท No AI or natural language guessing
- ๐ Applicable across scheduling, reporting, ETL, search systems, financial applications, etc.
๐ License
MIT License
๐ Related Alternatives
| Package | Approach | Difference from dateling |
|---|---|---|
dateparser |
Natural language parsing | No DSL, free-text interpretation |
parsedatetime |
Human language parsing | No formal syntax, heuristic parsing |
textX |
Generic DSL builder | Requires custom DSL grammar creation |
dateling |
DSL-based date expression language | Strict syntax for controlled date calculations |
๐งญ dateling: When you want to write date calculations, not guess them.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dateling-1.4.1.tar.gz.
File metadata
- Download URL: dateling-1.4.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4beef0d2ae7397ca9e0b9d31ff113b9d5b0dfab2a920f38cb4be0f2e5ff7ae56
|
|
| MD5 |
98550b3c69b3431dd32cc7d37e378f62
|
|
| BLAKE2b-256 |
b7f700804de7f06637792925adcb467ae84f4881eb2b72dde358211914e49d12
|
File details
Details for the file dateling-1.4.1-py3-none-any.whl.
File metadata
- Download URL: dateling-1.4.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9258111aa06bffc2e857921fa80290c7b7e96064e94fb0d17d5513820f26a874
|
|
| MD5 |
accac668d15c1346f647cdef6c00452e
|
|
| BLAKE2b-256 |
5c4ab0b5bdc2d4375b3129d85c987eeafa62f7f86e5ba1e2157dae95422bfbe6
|