A python module for locating dates within text.
Project description
datefind
A python module for locating dates within text. Use this package to search for dates and convert them to datetime objects.
Finds dates in many different formats.
- All numeric -
2024-01-01,01/01/2024,01012024 - Natural language -
January 1st, 2024,March nineteenth, 2024,twenty fifth of January - Fuzzy dates -
today,yesterday,tomorrow,last week,next week
[!NOTE]
datefind is designed to be used with year, month, and day only. It does not support hours, minutes, seconds, or microseconds.
Installation
Requires Python 3.11 or higher.
pip install datefind
Usage
from datefind import find_dates
string = "2024-01-01 and 2024-01-02"
for date in find_dates(string, tz="America/New_York"):
print(date)
>>> Date(
date=datetime.datetime(2024, 1, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')),
text='2024-01-01 and 2024-01-02',
match='2024-01-01',
span=(0, 10)
)
>>> Date(
date=datetime.datetime(2024, 1, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')),
text='2024-01-01 and 2024-01-02',
match='2024-01-02',
span=(15, 25)
)
find_dates
The find_dates() function is the main entry point for the datefind package. It takes a string of text and returns a generator of Date objects.
Arguments
text- The text to search for dates.first- The first number to find in ambiguous dates. (one ofmonth,day,year) Default ismonthtz- The timezone to use. Defaults to the local timezone.
For each date found, a Date object is returned. The Date object has the following properties:
date- The datetime object.text- The full original text.match- The matched portion of the text.span- The span of the matched text in the original text.
Contributing
See CONTRIBUTING.md for more information.
Project details
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 datefind-0.2.0.tar.gz.
File metadata
- Download URL: datefind-0.2.0.tar.gz
- Upload date:
- Size: 61.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf3c4bd4925b5ce5c9a41cbe46a0478ed1cd7d28954b359971da5a2d18a4a262
|
|
| MD5 |
f33e60e7f84cd635702db8c314f36d1e
|
|
| BLAKE2b-256 |
0a79d950b9b55bc743d789ee248efa588c72000f5cdc954dafabd7d45070319b
|
File details
Details for the file datefind-0.2.0-py3-none-any.whl.
File metadata
- Download URL: datefind-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be58ab793236a68776ccfff4c41b5f2c5b5aca49c48cb5ac36d90dedbc0573be
|
|
| MD5 |
99c84bf2e40e7d58d8c295ddaffc2c60
|
|
| BLAKE2b-256 |
186f10615e10e11d0f4b64a97e8d966a1170c1b59a86cba31b5696cac796e960
|