Skip to main content

Parse human-readable date/time strings.

Python 2.6 or greater is required for parsedatetime version 1.0 or greater.

While we still test with Python 2.6 we cannot guarantee that future changes will not break under 2.6

Downloads Travis CI Codecov Requirements Status Dependency Status

Installing

You can install parsedatetime using:

pip install parsedatetime

Running Tests

From the source directory:

make test

To run tests on several python versions, type make tox:

$ make tox
[... tox creates a virtualenv for every python version and runs tests inside of each]
py27: commands succeeded
py35: commands succeeded

This assumes that you have the versions you want to test under installed as part of your PyEnv environment:

pyenv install -s 2.6.9
pyenv install -s 2.7.11
pyenv install -s 3.5.2
pyenv install -s pypy-5.3
pyenv global 2.7.11 3.5.2 2.6.9 pypy-5.3

The tests depend on PyICU being installed using the pyicu-binary package which removes the source build step. PyICU depends on icu4c which on macOS requires homebrew:

brew install icu4c

The Makefile contains the macOS default values for them so you may need to tweak them.

Using parsedatetime

An example of how to use parsedatetime:

import parsedatetime

cal = parsedatetime.Calendar()

cal.parse("tomorrow")

To get it to a Python datetime object:

from datetime import datetime

time_struct, parse_status = cal.parse("tomorrow")

datetime(*time_struct[:6])

Parse datetime with timezone support (using pytz package):

import parsedatetime
import pytz
from pytz import timezone

cal = parsedatetime.Calendar()

datetime_obj, _ = cal.parseDT(datetimeString="tomorrow", tzinfo=timezone("US/Pacific"))

More detailed examples can be found in the examples directory.

Documentation

The generated documentation is included by default in the docs directory and can also be viewed online at https://bear.im/code/parsedatetime/docs/index.html

The docs can be generated by running:

make docs

Notes

The Calendar class has a member property named ptc which is created during the class init method to be an instance of parsedatetime_consts.CalendarConstants().

History

The code in parsedatetime has been implemented over the years in many different languages (C, Clipper, Delphi) as part of different custom/proprietary systems I’ve worked on. Sadly the previous code is not “open” in any sense of that word.

When I went to work for Open Source Applications Foundation and realized that the Chandler project could benefit from my experience with parsing of date/time text I decided to start from scratch and implement the code using Python and make it truly open.

After working on the initial concept and creating something that could be shown to the Chandler folks, the code has now evolved to its current state with the help of the Chandler folks, most especially Darshana.

Release files for parsedatetime 2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parsedatetime 2.6
File Size Uploaded
parsedatetime-2.6.tar.gz 60.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parsedatetime 2.6
File Interpreter ABI Platform
parsedatetime-2.6-py3-none-any.whl Python 3 none any Details

Total release size: 102.7 kB

Release files / parsedatetime-2.6.tar.gz

Download URL parsedatetime-2.6.tar.gz
Size 60.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4cb368fbb18a0b7231f4d76119165451c8d2e35951455dfee97c62a87b04d455
BLAKE2b-256 checksum
How to use checksums
a820cb587f6672dbe585d101f590c3871d16e7aec5a576a1694997a3777312ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.3

Release files / parsedatetime-2.6-py3-none-any.whl

Download URL parsedatetime-2.6-py3-none-any.whl
Size 42.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb96edd7016872f58479e35879294258c71437195760746faffedb692aef000b
BLAKE2b-256 checksum
How to use checksums
9da43dd804926a42537bf69fb3ebb9fd72a50ba84f807d95df5ae016606c976c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

2.6 This release

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0

2 release files

1.5

2 release files

1.4

2 release files

1.3

1 release file

1.2

1 release file

1.1.2

1 release file

1.1.1

1 release file

0.8.7

3 release files

0.8.6

3 release files

0.8.4

3 release files

0.8.3

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page