langdt is a Python library designed for natural language processing of time-related text. It translates various expressions and phrases that describe time into machine-readable datetime objects. langdt can interpret phrases like "yesterday", "last month", "since last year", and many more, providing a convenient way to work with time expressions in a human-friendly manner.
- Converts natural language to
datetime
objects. - Supports a wide range of time expressions.
- Handles both specific dates and relative timeframes.
To install langdt
, simply run:
pip install git+https://github.com/zozoheir/langdt.git@main
Here are a few examples of how langdt
can be used:
To get the datetime range for 'yesterday':
from langdt import get_timeframe
start_time, end_time = get_timeframe("yesterday")
print(f"Start: {start_time}, End: {end_time}")
To get the datetime range for 'last month':
from langdt import get_timeframe
start_time, end_time = get_timeframe("last month")
print(f"Start: {start_time}, End: {end_time}")
To get the datetime range between two specific dates:
from langdt import get_timeframe
start_time, end_time = get_timeframe("from 2022-01-01 to 2022-12-31")
print(f"Start: {start_time}, End: {end_time}")
Contributions are welcome! If you have an idea for an improvement or have found a bug, please open an issue or submit a pull request.
langdt
is released under the MIT License. See the LICENSE file for more details.