Skip to main content
https://img.shields.io/pypi/v/iso8601utils.svg https://travis-ci.org/silverfernsys/iso8601utils.svg?branch=master https://codecov.io/gh/silverfernsys/iso8601utils/branch/master/graph/badge.svg https://img.shields.io/pypi/l/iso8601utils.svg https://img.shields.io/pypi/status/iso8601utils.svg https://img.shields.io/pypi/implementation/iso8601utils.svg https://img.shields.io/pypi/pyversions/iso8601utils.svg https://img.shields.io/pypi/format/iso8601utils.svg https://img.shields.io/librariesio/github/silverfernsys/iso8601utils.svg

iso8601utils

Datastructures and utilities for representing, parsing, and validating ISO 8601 dates, times, date-times, durations, and intervals.

Datastructures

>>> from iso8601utils import parsers, interval, duration

# Intervals
>>> i = parsers.interval('R8/2016-08-01T23:10:59.111Z/2016-08-08T00:13:23.001Z')
>>> i
iso8601utils.interval(R8/2016-08-01T23:10:59.111000Z/2016-08-08T00:13:23.001000Z)

# Decompose interval into an (int, datetime, datetime, iso8601utils.duration)
# tuple representing (repeats, start, end, duration)
>>> tuple(i)
(8, datetime.datetime(2016, 8, 1, 23, 10, 59, 111000, tzinfo=Z), datetime.datetime(2016, 8, 8, 0, 13, 23, 1000, tzinfo=Z), iso8601utils.duration(P6DT1H2M23.89S))

# Public properties
>>> i.repeats
8
>>> i.start
datetime.datetime(2016, 8, 1, 23, 10, 59, 111000, tzinfo=Z)
>>> i.end
datetime.datetime(2016, 8, 8, 0, 13, 23, 1000, tzinfo=Z)
>>> i.duration
iso8601utils.duration(P6DT1H2M23.89S)

# Durations
>>> d = parsers.duration('P3Y6M4DT12H30M5S')
>>> d
iso8601utils.duration(P3Y6M4DT12H30M5S)

# Decompose duration into a (timedelta, monthdelta) tuple
>>> tuple(d)
(datetime.timedelta(4, 45005), MonthDelta(42))

# Public properties
>>> d.timedelta
datetime.timedelta(4, 45005)
>>> d.monthdelta
MonthDelta(42)

# Add and subtract durations with datetime objects
>>> from datetime import datetime
>>> dt = datetime(2016, 11, 4, 4, 49, 4)
>>> dt + d
datetime.datetime(2020, 5, 8, 17, 19, 9)
>>> dt - d
datetime.datetime(2013, 4, 30, 16, 18, 59)

# Add and subtract durations
>>> a = duration(years=1, months=5, days=3, hours=12)
>>> b = duration(days=2, hours=5)
>>> a + b
iso8601utils.duration(P1Y5M3DT17H)
>>> a - b
iso8601utils.duration(P1Y5M1DT7H)

# Compare durations
>>> a < b
False
>>> a > b
True

Parsers

>>> from iso8601utils import parsers

# Parse intervals
>>> parsers.interval('2016-08-01T23:10:59.111Z/2016-08-08T00:13:23.001Z')
iso8601utils.interval(2016-08-01T23:10:59.111000Z/2016-08-08T00:13:23.001000Z)

>>> parsers.interval('R5/2002-08-15T16:20:05.100+08:10/2002-10-12T17:05:25.020-01:40')
iso8601utils.interval(R5/2002-08-15T16:20:05.100000+08:10/2002-10-12T17:05:25.020000-01:40)

# Parse durations
>>> parsers.duration('P3Y6M4DT12H30M5S')
iso8601utils.duration(P3Y6M4DT12H30M5S)

# Parse times
>>> parsers.time('13:15+05:10')
datetime.time(13, 15, tzinfo=+05:10)

# Parse dates
>>> parsers.date('1981-04-05')
datetime.date(1981, 4, 5)

# Parse datetimes
>>> parsers.datetime('2007-08-09T12:30-02:00')
datetime.datetime(2007, 8, 9, 12, 30, tzinfo=-02:00)

# Parse ordinal dates
>>> parsers.date('1981-095')
datetime.date(1981, 4, 5)

# Parse week dates
>>> parsers.date('2016-W43-1')
datetime.date(2016, 10, 24)

Validators

# Validate strings
>>> from iso8601utils import validators
>>> validators.interval('1999-12-31T16:00:00.000+04:00/P5DT7H')
True
>>> validators.interval('23P7DT5H')
False
>>> validators.duration('P3Y6M4W7DT12H30M5S')
True
>>> validators.duration('23P7DT5H')
False
>>> validators.time('13:15+05:10')
True
>>> validators.date('1981-04-05')
True
>>> validators.date('1981-095')
True
>>> validators.date('1981-W43-1')
True
>>> validators.date('1981W43-1')
False

Metadata

Release files for iso8601utils 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iso8601utils 0.1.2
File Size Uploaded
iso8601utils-0.1.2.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iso8601utils 0.1.2
File Interpreter ABI Platform
iso8601utils-0.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 25.5 kB

Release files / iso8601utils-0.1.2.tar.gz

Download URL iso8601utils-0.1.2.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
59138b8337ed48e94e46df617557a1bf5fd11233409911e3453eb09a3d58b670
BLAKE2b-256 checksum
How to use checksums
f3190290cdc2bed6746a2a0b1b501280c85f422efcea4c4a83aeff5b0093253a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / iso8601utils-0.1.2-py2.py3-none-any.whl

Download URL iso8601utils-0.1.2-py2.py3-none-any.whl
Size 13.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b03b47cc006bcb68badffa9b71513553e64fae0e0d14ead0bcb48b90778eed04
BLAKE2b-256 checksum
How to use checksums
fba34246342d9bf5c6522747cbd76950d9edb5579108e91b4e26128292e5d269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
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