Package: isodate
ISO 8601 date/time parserThis 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.DocumentationCurrently there are four 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.Installation:This module can easily be installed with Python standard installation methods.Either usepython setup.py installor in case you havesetuptoolsordistributeavailable, you can also useeasy_install.Limitations:The 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 information:The 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 athttp://github.com/gweis/isodate.CHANGES0.6.1 (2021-12-13)support python 3.10 ()last version to support py 2.70.6.0 (2017-10-13)support incomplete month date (Fabien Loffredo)rely on duck typing when doing duration mathssupport ‘:’ as separator in fractional time zones (usrenmae)0.5.4 (2015-08-06)Fix parsing of Periods (Fabien Bochu)Make Duration objects hashable (Geoffrey Fairchild)Add multiplication to duration (Reinoud Elhorst)0.5.1 (2014-11-07)fixed pickling of Duration objectsraise ISO8601Error when there is no ‘T’ separator in datetime strings (Adrian Coveney)0.5.0 (2014-02-23)ISO8601Error are subclasses of ValueError now (Michael Hrivnak)improve compatibility across various python variants and versionsraise exceptions when using fractional years and months in date
maths with durationsrenamed method todatetime on Duraction objects to totimedelta0.4.9 (2012-10-30)support pickling FixedOffset instancesmake sure parsed fractional seconds are in microsecondsadd leading zeros when formattig microseconds (Jarom Loveridge)0.4.8 (2012-05-04)fixed incompatibility of unittests with python 2.5 and 2.6 (runs fine on 2.7
and 3.2)0.4.7 (2012-01-26)fixed tzinfo formatting (never pass None into tzinfo.utcoffset())0.4.6 (2012-01-06)added Python 3 compatibility via 2to30.4.5 (2012-01-06)made setuptools dependency optional0.4.4 (2011-04-16)Fixed formatting of microseconds for datetime objects0.4.3 (2010-10-29)Fixed problem with %P formating and fractions (supplied by David Brooks)0.4.2 (2010-10-28)Implemented unary - for Duration (supplied by David Brooks)Output fractional seconds with ‘%P’ format. (partly supplied by David Brooks)0.4.1 (2010-10-13)fixed bug in comparison between timedelta and Duration.fixed precision problem with microseconds (reported by Tommi Virtanen)0.4.0 (2009-02-09)added method to parse ISO 8601 time zone stringsadded methods to create ISO 8601 conforming strings0.3.0 (2009-1-05)Initial releaseTODOsThis to do list contains some thoughts and ideas about missing features, and
parts to think about, whether to implement them or not. This list is probably
not complete.Missing features:time formating does not allow to create fractional representations.parser for ISO intervals.currently microseconds are always padded to a length of 6 characters.
trailing 0s should be optionalDocumentation:parse_datetime:complete documentation to show what this function allows, but ISO forbids.
and vice verse.support other separators between date and time than ‘T’parse_date:yeardigits should be always greater than 4dates before 0001-01-01 are not supportedparse_duration:alternative formats are not fully supported due to parse_date restrictionsstandard duration format is fully supported but not very restrictive.Duration:support fractional years and month in calculationsimplement w3c order relation? (http://www.w3.org/TR/xmlschema-2/#duration-order)refactor to have duration mathematics only at one place.localize __str__ method (does timedelta do this?)when is a Duration negative?normalize Durations. months [00-12] and years ]-inf,+inf[