PySO8601 aims to be a better Python module to parse ISO 8601 dates. It is inspired by the iso8601 currently available in the pypi repository, however this module is designed to accept any valid ISO8601 formatted string:
Truncated representations (YYYYMM, YYMMDD, hhmmss, etc) are also accepted.
import PySO8601
spam = PySO8601.parse('2011-01-01T14:32')
print spam # prints: 2011-01-01 14:32:00
eggs = PySO8601.parse('2010W052') # Week 5, day 2
print eggs # prints: 2010-02-01 00:00:00
For full examples on usage please review the specs in the source.
Attempts to parse an ISO8601 formatted representation string, which could be of any valid ISO8601 format (date, time, duration, interval).
Return value is specific to representation.
Attepmts to parse an ISO8601 formatted datestring.
Returns a datetime.datetime object.
Attepmts to parse an ISO8601 formatted timestring.
Returns a datetime.datetime object.
Attepmts to parse an ISO8601 formatted duration.
Returns a datetime.timedelta object.
Attepmts to parse an ISO8601 formatted interval.
Returns a tuple of datetime.datetime and datetime.timedelta objects, order dependent on interval.
A subclass of datetime.tzinfo which handles timezone offsets for the various other methods in the module.
tzstring accepts a valid ISO8601 timezone string or None for UTC.
datetime in UTC -> datetime in local time.
datetime -> string name of time zone.
Returned when there is a formatting error with the argument(s)