I work with a codebase with a lot of date fields similar to:
orderDetails = {
"deliveryDate": datetime.date(2023, 12, 31),
"paymentDate" : datetime.date(2024, 1, 5),
}
This is very verbose.
One could make it less verbose by switching to “dt.date(2023, 12, 31)”, but this still depends on presence of “import datetime as dt” above.
Instead, I propose to allow date literals to be declared using pattern “\d\d\d\d_\d\d_\d\d”, for example 1999_01_01:
deliveryDate = 2023_12_31 # proposed. Would evaluate to datetime.date(2023,12,31)
deliveryDate = 2023_12_32 # proposed - would throw "SyntaxError: day is out of range for month"
P.S. This new syntax would override PEP515 for this exact pattern.
References:
- ISO 8601 (ISO - ISO 8601 — Date and time format).
- PEP515 allows"underscored literals"
- KDB vector database allows date literals to be declared using “dot syntax” - // link: Data types | Basics | kdb+ and q documentation - Kdb+ and q documentation
deliveryDate = 2023-12-31 # ISO-like syntax unfortunately evaluates to 1980
deliveryDate = 2023_12_31 # PEP515 syntax, evaluates to integer 20231231
deliveryDate: 2023.12.31 // KDB date literal syntax