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
  • 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')),
    match='2024-01-01',
    span=(0, 10)
    )
>>> Date(
    date=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 Date object is returned. The Date object has the following properties:

  • date - 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.2.1.tar.gz (61.6 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.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: datefind-0.2.1.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

Hashes for datefind-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b03690290693d64aae14d2fff99d4b8e847d8f6a561952c19ca9b74b974ecadd
MD5 e3618f93855389e056048e03ccb21242
BLAKE2b-256 3db3607fe6584bf5a9120624d29fd695217c0ced051c61b1cb5c917d3910237c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datefind-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for datefind-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee942dc1d1b5bfa62da5776139f7c055900afe90cab24b1ef88e227e239f786b
MD5 111b6c0fedc377d714e41b4fc364b0c2
BLAKE2b-256 f9cc2b669a4054cc1f885d1b2b432f1781006d1fe155a9638ce734cdfc66e62a

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