Package: isodate2
ISO 8601 date/time parserisodate2 is a fork of isodateThis module implements ISO 8601 date, time and duration parsing.
The implementation follows ISO8601:2004 standard, and implements only
date/time representations mentioned in the standard. If something is not
mentioned there, then it is treated as non-existent, and not as an allowed
option.For instance, ISO8601:2004 never mentions 2 digit years. So, it is not
intended by this module to support 2 digit years. (while it may still
be valid as ISO date, because it is not explicitly forbidden.)
Another example is, when no time zone information is given for a time,
then it should be interpreted as local time, and not UTC.As this module maps ISO 8601 dates/times to standard Python data types, likedate,time,datetimeandtimedelta, it is not possible to convert
all possible ISO 8601 dates/times. For instance, dates before 0001-01-01 are
not allowed by the Pythondateanddatetimeclasses. Additionally
fractional seconds are limited to microseconds. That means if the parser finds
for instance nanoseconds it will round it to microseconds.DocumentationThere are five parsing methods available.parse_time:
parses an ISO 8601 time string into atimeobjectparse_date:
parses an ISO 8601 date string into adateobjectparse_datetime:
parses an ISO 8601 date-time string into adatetimeobjectparse_duration:
parses an ISO 8601 duration string into atimedeltaorDurationobject.parse_tzinfo:
parses the time zone info part of an ISO 8601 string into atzinfoobject.As ISO 8601 allows to define durations in years and months, andtimedeltadoes not handle years and months, this module provides aDurationclass,
which can be used almost like atimedeltaobject (with some limitations).
However, aDurationobject can be converted into atimedeltaobject.There are also ISO formatting methods for all supported data types. Eachxxx_isoformatmethod accepts a format parameter. The default format is
always the ISO 8601 expanded format. This is the same format used bydatetime.isoformat:time_isoformat:
Intended to create ISO time strings with default formathh:mm:ssZ.date_isoformat:
Intended to create ISO date strings with default formatyyyy-mm-dd.datetime_isoformat:
Intended to create ISO date-time strings with default formatyyyy-mm-ddThh:mm:ssZ.duration_isoformat:
Intended to create ISO duration strings with default formatPnnYnnMnnDTnnHnnMnnS.tz_isoformat:
Intended to create ISO time zone strings with default formathh:mm.strftime:
A re-implementation mostly compatible with Python'sstrftime, but
supports only those format strings, which can also be used for dates
prior 1900. This method also understands how to formatdatetimeandDurationinstances.Installationpython-mpipinstallisodate2LimitationsThe parser accepts several date/time representation which should be invalid
according to ISO 8601 standard.for date and time together, this parser accepts a mixture of basic and extended format.
e.g. the date could be in basic format, while the time is accepted in extended format.
It also allows short dates and times in date-time strings.For incomplete dates, the first day is chosen. e.g. 19th century results in a date of
1901-01-01.negativeDurationandtimedeltavalue are not fully supported yet.Further informationThe doc strings and unit tests should provide rather detailed information about
the methods and their limitations.The source release provides asetup.pyscript,
which can be used to run the unit tests included.Source code is available athttps://github.com/isodate/isodate.See alsoisodurationis a well-maintained library which
aims to improve upon isodate:The state of the art of ISO 8601 duration handling in Python is more or less limited
to what's offered byisodate. What we are
trying to achieve here is to address the shortcomings ofisodate(as described in
their ownLimitationssection), and
a few of our own annoyances with their interface, such as the lack of uniformity in
their handling of types, and the use of regular expressions for parsing.