chrono.parser.ISOParser - ISO 8601 parser

class chrono.parser.ISOParser

A parser for ISO 8601 date formats, using the ISO calendar. For more information on the ISO calendar, see the chrono.calendar.ISOCalendar documentation.

The most commonly used ISO formats are yyyy-mm-dd and yyyy-mm-dd hh:mm:ss, but the standard specifies a range of formats, listed below. Datetimes can be composed of any combination of the date and time formats listed, separated by whitespace or a T.

Format Example Description Method
yyyy-mm-dd 2009-12-27 Date chrono.parser.ISOParser.date()
hh:mm:ss 15:27:43 Time [1] chrono.parser.ISOParser.time()
yyyy-ddd 2009-163 Ordinal day chrono.parser.ISOParser.ordinal()
yyyy-Www-d 2009-W36-3 Week and weekday chrono.parser.ISOParser.weekdate()
yyyy-Www 2009-W36 Week chrono.parser.ISOParser.week()
yyyy-mm 2009-12 Month chrono.parser.ISOParser.month()
yyyy 2009 Year chrono.parser.ISOParser.year()
yyyymmdd 20091227 Compact date chrono.parser.ISOParser.compactdate()
hhmmss 152743 Compact time [1] chrono.parser.ISOParser.compacttime()
yyyyddd 2009163 Compact ordinal day chrono.parser.ISOParser.compactordinal()
yyyyWwwd 2009W363 Compact week and day chrono.parser.ISOParser.compactweekdate()
yyyyWww 2009W36 Compact week chrono.parser.ISOParser.compactweek()
[1](1, 2) Seconds and minutes may be omitted in times
classmethod compactdate(date)

Parses a compact ISO date (yyyymmdd), and returns a tuple with year, month, and day.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError, chrono.error.MonthError, or chrono.error.DayError for invalid date values.

classmethod compactordinal(date)

Parses a compact ISO ordinal date (yyyyddd), and returns a tuple with year and ordinal day.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError or chrono.error.DayError for invalid date values.

classmethod compacttime(time)

Parses a compact ISO time (hhmmss), and returns a tuple with hour, minute, and second. Minutes and/or seconds may be omitted, which will be interpreted as 0.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.HourError, chrono.error.MinuteError, or chrono.error.SecondError for invalid time values.

classmethod compactweek(date)

Parses a compact ISO week (yyyyWww), and returns a tuple with year and week number. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError or chrono.error.WeekError for invalid date values.

classmethod compactweekdate(date)

Parses a compact ISO weekdate (yyyyWwwd), and returns a tuple with year, week, and weekday.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError, chrono.error.WeekError, or chrono.error.DayError for invalid date values.

classmethod date(date)

Parses a ISO date (yyyy-mm-dd), and returns a tuple with year, month, and day. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError, chrono.error.MonthError, or chrono.error.DayError for invalid date values.

classmethod month(date)

Parses an ISO month (yyyy-mm), and returns a tuple with year and month. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError or chrono.error.MonthError for invalid date values.

classmethod ordinal(date)

Parses an ISO ordinal date (yyyy-ddd), and returns a tuple with year and ordinal day.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError or chrono.error.DayError for invalid date values.

classmethod parse_date(date)

Parses an ISO date in any supported format, and returns a tuple with year, month, and day. For formats which doesn’t provide data with day precision, the earliest possible day is used - for example, 2009-W32 would return (2009, 8, 3), the Monday of week 32 2009.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and an appropriate chrono.error.DateError subclass for invalid date values.

classmethod parse_datetime(datetime)

Parses an ISO datetime in any supported format and returns a tuple with year, month, day, hour, minute, and second. Omitted minutes and/or seconds will be interpreted as 0.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and an appropriate chrono.error.DateTimeError subclass for invalid datetime values.

classmethod parse_time(time)

Parses an ISO time in any supported format and returns a tuple with hour, minutes, and seconds. Omitted minutes and/or seconds will be interpreted as 0.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and an appropriate chrono.error.TimeError subclass for invalid time values.

classmethod time(time)

Parses an ISO time (hh:mm:ss), and returns a tuple with hour, minute, and second. Minutes and/or seconds may be omitted, which will be interpreted as 0. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.HourError, chrono.error.MinuteError, or chrono.error.SecondError for invalid time values.

classmethod week(date)

Parses an ISO week (yyyy-Www), and returns a tuple with year and week number. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError or chrono.error.WeekError for invalid date values.

classmethod weekdate(date)

Parses an ISO weekdate (yyyy-Www-d), and returns a tuple with year, week, and weekday. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError, chrono.error.WeekError, or chrono.error.DayError for invalid date values.

classmethod year(date)

Parses an ISO year (yyyy), and returns it. Leading zeroes may be omitted, even though the ISO standard requires them.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.YearError for invalid year value.

Previous topic

chrono.parser.Parser - Base class for parsers

Next topic

chrono.utility - Utility functions