Delta is a Python library designed for human-friendly, context-aware parsing of duration strings. It allows users to convert natural language descriptions of time durations (e.g., '1 year 2 months and 3 days') into `datetime.timedelta` objects, optionally considering a specific start date for accurate calculations (e.g., for '2 months' relative to January vs. April). The library is currently at version 0.4.2 and appears to have a low release cadence.
pip install deltaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `delta.parse()` function to interpret various human-readable duration strings. It shows examples with and without an explicit context date, highlighting how 'context-aware' parsing works for units like months.
Consider testing thoroughly with your specific Python version and use case. For active development, explore alternatives like `pendulum` or `dateutil` if they meet your parsing needs.
Always provide an explicit `datetime` object as the `context` argument to `delta.parse()` for reproducible and consistent duration calculations, especially when dealing with non-fixed time units like months or years.
Ensure the `context` `datetime` objects are consistent with the expected timezone behavior of your application. If precise timezone handling is critical, consider pre-processing your `datetime` objects or using a library with explicit timezone support.
Test the library with the full range of expected input strings in your application. Implement robust error handling around `delta.parse()` calls to gracefully manage potential parsing failures.
Ensure the correct 'delta' duration parsing library is installed: `pip install python-delta`.
Provide a valid duration string, such as '1 day', '2 hours', '3.5 weeks', or '1y 2m 3d'.
Ensure that the `context_date` argument is a valid `datetime.datetime` object.
No dependency data recorded yet.