Skip to main content

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.

Future (in no particular order):

  • Support timezones

  • Support durations

  • 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.1.5 - Added support for fractional times.

0.1.1 - Helps if I spell my domain name right.

0.1 - Initial release.

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

iso-8601-0.1.5.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file iso-8601-0.1.5.tar.gz.

File metadata

  • Download URL: iso-8601-0.1.5.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for iso-8601-0.1.5.tar.gz
Algorithm Hash digest
SHA256 e530a03d74180e9630ee939b8666a54da6fc8e997f96129fcaea0f63fdccf7f4
MD5 a871c5683ca0dd49a45524cc1bd668af
BLAKE2b-256 23cbdacfeca4b10687a314bc3208b81ef1b7cf858c3484d76a3deba4afafd7fa

See more details on using hashes here.

Supported by

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