Skip to main content

Simple module to parse ISO 8601 dates

Project description

Simple module to parse ISO 8601 dates

pip install iso8601

Documentation: https://pyiso8601.readthedocs.org/

PyPI: https://pypi.org/project/iso8601/

Source: https://github.com/micktwomey/pyiso8601

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.

References

Testing

  1. poetry install

  2. poetry run nox

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. poetry install

  2. pytest

Releasing

  1. just prepare-release

  2. just do-release

Supported Python Versions

Tested against:

  • Python 3.7

  • Python 3.8

  • Python 3.9

  • Python 3.10

  • Python 3.11

  • Python 3.12

  • PyPy 3

Python 3 versions < 3.7 are untested but should work.

Changes

See CHANGELOG.md.

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-2.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

iso8601-2.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iso8601-2.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Darwin/22.5.0

File hashes

Hashes for iso8601-2.0.0.tar.gz
Algorithm Hash digest
SHA256 739960d37c74c77bd9bd546a76562ccb581fe3d4820ff5c3141eb49c839fda8f
MD5 4b6b6c90a17845c03e99efbefea834d0
BLAKE2b-256 272397cd1cb5792ece594ec5cf16cc4921f91838c689c82c8078ee442751f8dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iso8601-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Darwin/22.5.0

File hashes

Hashes for iso8601-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe10061b932edb8a8e33cc635d661926c59b9c3bed7a4f4edca8c62d400af10
MD5 feb7b630b5651ed1d41aa2c10ad1ebec
BLAKE2b-256 12e4032a8569b75a79057f0c72b4f4a69434fd21922bce7bfe054e0e9f367861

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