Skip to main content

Simple module to parse ISO 8601 dates

Project description

Simple module to parse ISO 8601 dates

This module parses the most common forms of ISO 8601 date strings (e.g. 2007-01-14T20:34:22+00:00) into datetime objects.

>>> import iso8601
>>> iso8601.parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc>)
>>>

See the LICENSE file for the license this package is released under.

If you want more full featured parsing look at:

Parsed Formats

You can parse full date + times, or just the date. In both cases a datetime instance is returned but with missing times defaulting to 0, and missing days / months defaulting to 1.

Dates

  • YYYY-MM-DD

  • YYYYMMDD

  • YYYY-MM (defaults to 1 for the day)

  • YYYY (defaults to 1 for month and day)

Times

  • hh:mm:ss.nn

  • hhmmss.nn

  • hh:mm (defaults to 0 for seconds)

  • hhmm (defaults to 0 for seconds)

  • hh (defaults to 0 for minutes and seconds)

Time Zones

  • Nothing, will use the default timezone given (which in turn defaults to UTC).

  • Z (UTC)

  • +/-hh:mm

  • +/-hhmm

  • +/-hh

Where it Differs From ISO 8601

Known differences from the ISO 8601 spec:

  • You can use a “ “ (space) instead of T for separating date from time.

  • Days and months without a leading 0 (2 vs 02) will be parsed.

  • If time zone information is omitted the default time zone given is used (which in turn defaults to UTC). Use a default of None to yield naive datetime instances.

Homepage

This was originally hosted at https://code.google.com/p/pyiso8601/

References

Testing

  1. pip install -r dev-requirements.txt

  2. tox

Note that you need all the pythons installed to perform a tox run (see below). pyenv helps hugely, use pyenv install for the versions you need then use ‘pyenv local version …’ to link them in (the tox-pyenv plugin will pick them up).

Alternatively, to test only with your current python:

  1. pip install -r dev-requirements.txt

  2. py.test –verbose iso8601

Supported Python Versions

Tested against:

  • Python 2.7

  • Python 3.5

  • Python 3.6

  • Python 3.7

  • Python 3.8

  • PyPy

  • PyPy 3

Python 3.0, 3.1 and 3.2 are untested but should work (tests didn’t run under them when last tried).

Jython is untested but should work (tests failed to run).

Python 2.5 is not supported (too old for the tests for the most part). It could work with some small changes but I’m not supporting it.

Changes

Unreleased

0.1.13

  • Move to GitHub (https://github.com/micktwomey/pyiso8601). Thanks go to Martin Häcker for pointing out the bitbucket project had been deleted by Atlassian!

  • Remove python 2.6, 3.2, 3.3 and 3.4 from tests

  • Add python 3.7 and 3.8 to tests

0.1.12

0.1.11

0.1.10

0.1.9

0.1.8

0.1.7

0.1.6

0.1.5

0.1.4

  • The default_timezone argument wasn’t being passed through correctly, UTC was being used in every case. Fixes issue 10.

0.1.3

  • Fixed the microsecond handling, the generated microsecond values were way too small. Fixes issue 9.

0.1.2

  • Adding ParseError to __all__ in iso8601 module, allows people to import it. Addresses issue 7.

  • Be a little more flexible when dealing with dates without leading zeroes. This violates the spec a little, but handles more dates as seen in the field. Addresses issue 6.

  • Allow date/time separators other than T.

0.1.1

  • When parsing dates without a timezone the specified default is used. If no default is specified then UTC is used. Addresses issue 4.

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

iso8601-0.1.13.tar.gz (12.2 kB view details)

Uploaded Source

Built Distributions

iso8601-0.1.13-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

iso8601-0.1.13-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file iso8601-0.1.13.tar.gz.

File metadata

  • Download URL: iso8601-0.1.13.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for iso8601-0.1.13.tar.gz
Algorithm Hash digest
SHA256 f7dec22af52025d4526be94cc1303c7d8f5379b746a3f54a8c8446384392eeb1
MD5 df6e924305fd799d90be63336b2ab8b3
BLAKE2b-256 05902d9927dc2d33192f58fe39d2d216313a8380625cd4b062efb93f1afd7a29

See more details on using hashes here.

File details

Details for the file iso8601-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: iso8601-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for iso8601-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 6f02f01dd13320a7f280e58516dc8d1950dfaf77527cc365a398cd9de4d3c692
MD5 cf25731432fb404c06336086d71691cb
BLAKE2b-256 98ad5b6342bec1ce40b5f4783fa552f10109e159b734909d11a71513b240d7dd

See more details on using hashes here.

File details

Details for the file iso8601-0.1.13-py2.py3-none-any.whl.

File metadata

  • Download URL: iso8601-0.1.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for iso8601-0.1.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 694be0743e9f1535ea873bfc7bd6fb62380c62b75822761859428073a17fd39c
MD5 919023d0c42704e1496b0319940cd2ea
BLAKE2b-256 f5c706b5938e79a09112a256f26a1ae0551b04bc6aafcb71fd7ee2390c2c54c6

See more details on using hashes here.

Supported by

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