A comprehensive Python library for advanced date and time manipulation.
Project description
📅 dately 📅
Comprehensive Date, Time & Natural-Language Handling in Python
dately is an end-to-end date-and-time toolkit that now pairs its high-precision formatting utilities with a mini natural-language-processing (NLP) engine. Whether you feed it an ISO-8601 timestamp, a plain month/day string, or a phrase like “second Tuesday of next quarter”, dately can turn it into an exact datetime object or (start, end) range.
Table of Contents
Why Choose dately?
- Windows Optimized – fixes
%‐m/#zero-suppression inconsistencies on Windows. - NLP Inside – understands expressions such as “last 5 weekends”, “Q4 2026”, “3 days ago starting from April 10”.
- Comprehensive API – parsing, detection, extraction and conversion for raw strings,
datetimeobjects, pandas Series, NumPy arrays and free-text phrases. - High Performance – Python + Cython hot-paths for heavy string/date workloads.
Key Features
- Date and Time Format Detection:
- Automatically detect various date and time formats from strings, ensuring seamless parsing and conversion.
- Supports a wide range of date formats, including standard and unique custom formats.
- Timezone Management:
- Provides detailed information for specific time zones.
- Converts time from one time zone to another.
- Retrieves the current time for specific time zones.
- Categorizes time zones by country, offset, and daylight saving time observance.
- String Manipulation and Validation:
- Extract specific components (year, month, day, hour, minute, second, timezone) from datetime strings.
- Validate and replace parts of datetime strings to ensure accuracy and consistency.
- Strip time and timezone information from datetime strings when needed.
- Performance Optimizations:
- Utilizes Cython to enhance performance for computationally intensive tasks.
- Interfaces with underlying C code to perform high-speed string operations and date validations.
- Natural-Language Parsing (new!)
- Relative phrases
"next 2 Fridays" → [date, date] - Range phrases
"first half of last year" - Anchored clauses
"start of Q3 2024" - Token normalisation (cardinal ↔︎ ordinal words, plural handling, etc.)
- Rule-based NLP pipeline: tokenisation → normalisation → pattern matching → date algebra.
- Relative phrases
Solving Windows Date Formatting Issues
A key aspect of this module is addressing inconsistencies in Python's date formatting on the Windows operating system. The module specifically targets the handling of the hyphen-minus (-) in date format specifiers. This flag, used to remove leading zeros from formatted output (e.g., turning '01' into '1' for January), works reliably on Unix-like systems but does not function as intended on Windows.
To solve this problem on Windows, the dately module introduces a workaround using regular expressions. It utilizes a detection function to determine the format string and then examines each date component for leading zeros through an extract_date_component function and a subsequent has_leading_zero check. Depending on the presence of leading zeros, the module adjusts the format string-replacing %m with %-m where applicable-to emulate the behavior expected from the hyphen-minus on Unix-like systems.
This method ensures that users on Windows achieve consistent date formatting, effectively compensating for the lack of native support for the hyphen-minus in date specifiers on this system.
Overall, dately is a powerful utility for anyone needing precise and flexible date and time handling in their applications, making it easier to manage, format, and validate date and time data consistently and efficiently.
Usage Examples - Working with Date Strings
To keep this README focused, all full-length usage examples are now available in the examples/ folder.
You can explore them here:
- Date Conversion & Formatting
- Replacing Date Parts
- Time Zone Operations
- Natural Language Parsing (NLP)
Each file contains runnable code with expected outputs.
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 dately-3.2.4.tar.gz.
File metadata
- Download URL: dately-3.2.4.tar.gz
- Upload date:
- Size: 793.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d49505718adc380a240c51623e273509d4f1d9338bf6053af3951bc028f46c0
|
|
| MD5 |
a4a4184e2230c25ec3fdc531a0299f12
|
|
| BLAKE2b-256 |
642023644b2979e5d418b4a430098f35abcc9f0866dc326411922834248de3eb
|
File details
Details for the file dately-3.2.4-py3-none-any.whl.
File metadata
- Download URL: dately-3.2.4-py3-none-any.whl
- Upload date:
- Size: 829.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77d72fc70b40ad2bd8ecbc70893f2b7d80c16495d38ad904ca30987ac36c5137
|
|
| MD5 |
5b08ba74368378c8ef5d297531650867
|
|
| BLAKE2b-256 |
cccaf4abfbf094239af13b2cd580b523fc2bba10391b8e9cf52a426cba7962b0
|