Skip to main content

A python module for locating dates within text.

Project description

Tests codecov

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, etc.
  • Natural language - January 1st, 2024, March nineteenth, 2024, twenty fifth of January, Mar 15, 24, etc.
  • Fuzzy dates - today, yesterday, tomorrow, last week, this week, next week, etc.
  • Relative offsets - 3 days ago, in 2 weeks, 1 year from now, etc.
  • Weekdays - Monday, next Friday, last Tuesday, etc.
  • Quarters - Q1 2024, 2024 Q3, etc.

[!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)

>>> FoundDate(
        datetime=datetime.datetime(2024, 1, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')),
        match='2024-01-01',
        span=(0, 10)
    )
>>> FoundDate(
        datetime=datetime.datetime(2024, 1, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')),
        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 of month, day, year) Default is month
  • tz - The timezone to use. Defaults to the local timezone.

For each date found, a FoundDate object is returned. The FoundDate object has the following properties:

  • datetime - The datetime object.
  • 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

datefind-0.5.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datefind-0.5.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file datefind-0.5.0.tar.gz.

File metadata

  • Download URL: datefind-0.5.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for datefind-0.5.0.tar.gz
Algorithm Hash digest
SHA256 da5c675c81a113294c30f4d0b4edc0872f34fc5060cef54eb7253315aeddb93c
MD5 07ee395d4e7e000d40c611ac95deabed
BLAKE2b-256 9209851e93c10836a54cc3da1c4e6f1ce043c482608c25e6d3e414c03a543bf3

See more details on using hashes here.

File details

Details for the file datefind-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: datefind-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for datefind-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15771d2f2780239220d2af3eedf3210aa847bf641c2ca81f9febb65f7a9c7237
MD5 cd769b2a37cda62f9c899bccb2244758
BLAKE2b-256 989c4763cb4b9bc44249bdd90d2f4f860760fc30c53dede08cd84b169b08f1ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page