This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Flexible ISO 8601 parser: pass in a valid ISO 8601 string, and a datetime object will be returned.

Project Description

Correctly parse a valid ISO 8601 datetime string.

At this stage, only datetime (or non-truncated date) formats are permitted.

Week number formats are not permitted in this version.

You can have an object in any of the following formats:

  • YYYY-MM-DD
  • YYYYMMDD
  • YYYY-MM-DDThh
  • YYYYMMDDThh
  • YYYY-MM-DDThh:mm
  • YYYYMMDDThhmm
  • YYYY-MM-DDThh:mm:ss
  • YYYYMMDDThhmmss

Additionally, to support some legacy systems, in all cases the T can be replaced by a space. Essentially, this just combines the two representations, which is not strictly according to the specification, but is commonly used.

Also supported is using an hour of 24 to mean midnight at the end of the day: this is converted to the python object of the next day’s 00:00:00. Using a non-zero minute/second/fraction will raise a ValueError.

A fractional value may be appended to the last component of a time part. Appending it elsewhere will raise a ValueError.

Finally, only naive datetime objects are supported at this time. Timezones may not be included in the format string.

Duration time formats of the following forms are also supported:

  • P1W2DT3H4M5S

Note that support for Year and Month data is not supported, as this does not make sense with python’s timedelta object.

You may, as per ISO8601, drop fields that have no value.

Future (in no particular order):

  • Support timezones
  • Support durations fully
  • Support time intervals
  • Support repeating intervals
  • Support week-dates
  • Support truncated dates
  • Support time only objects (including truncated?)

The following references were used to determine supported formats:

Changelog:

0.2.4 - Workaround for errors when using freezegun.

0.2.3 - Added parse_date to module exports.

0.2.2 - Add methods for forcing return of a date (or time): parse_date()

0.2.1 - Initial support for duration data (excluding year/month).
  • Initial support for formatting objects.

0.1.6 - Allow for a date or datetime object to be passed to parse.

0.1.5 - Added support for fractional times.

0.1.1 - Helps if I spell my domain name right.

0.1 - Initial release.

Release History

Release History

This version
History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2a2

History Node

0.2a

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.1

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
iso-8601-0.2.4.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Jun 17, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting