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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iso8601utils-0.1.2.tar.gz | 11.8 kB | Without provenance | Details for iso8601utils-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iso8601utils-0.1.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for iso8601utils-0.1.2-py2.py3-none-any.whl |
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 |
Security for iso8601utils 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.