Skip to main content

parsedatetime

Parse human-readable date/time strings.

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

Downloads Travis CI Codecov Requirements 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 tox:

$ 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 python2.7, python3.5, etc in PATH.

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
from time import mktime

time_struct, parse_status = cal.parse("tomorrow")
datetime.fromtimestamp(mktime(time_struct))

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 it’s current state with the help the Chandler folks, most especially Darshana.

Metadata

Release files for parsedatetime 2.0

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.0
File Size Uploaded
parsedatetime-2.0.tar.gz 56.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parsedatetime 2.0
File Interpreter ABI Platform
parsedatetime-2.0-py2-none-any.whl Python 2 none any Details

Total release size: 94.0 kB

Release files / parsedatetime-2.0.tar.gz

Download URL parsedatetime-2.0.tar.gz
Size 56.1 kB
Tags Source
SHA-256 checksum
How to use checksums
74aaed8e8639842ff48c05c1e3708a26ffa138eb00d557be6681b5df771f7c8c
BLAKE2b-256 checksum
How to use checksums
09a8855e2f53d815a8215123a7ec37e3dae675e20d74af40f9c550e29748ee6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parsedatetime-2.0-py2-none-any.whl

Download URL parsedatetime-2.0-py2-none-any.whl
Size 37.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
9be60b878b50eb9cf65a0d32e7652f593ca76c0d8cf361ab0f2bff0771a33933
BLAKE2b-256 checksum
How to use checksums
410fa44a1baf6bae2a7a64fe256c016abd7a42e3ac2878b12febb05a0902a2dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.6

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

This release

2.0 This release

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