chrono.parser.CommonParser - Parser for most common formats

class chrono.parser.CommonParser

A parser for the most common date and time formats. Only the methods chrono.parser.CommonParser.parse_date(), chrono.parser.CommonParser.parse_datetime(), and chrono.parser.CommonParser.parse_time(), are implemented here, methods for individual formats can be found in the classes chrono.parser.EuroParser, chrono.parser.ISOParser, and chrono.parser.USParser.

Valid formats:

Format Example Description
yyyy-mm-dd 2009-12-27 ISO date
mm/dd/yyyy 07/23/2010 US date
dd.mm.yyyy 23.07.2010 European date
yyyy-ddd 2009-163 ISO ordinal date
yyyy-Www-d 2009-W36-3 ISO weekdate
yyyy-Www 2009-W36 ISO week
yyyy-mm 2009-12 ISO month
yyyy 2009 ISO year
hh:mm:ss 16:27:43 ISO time
hhmmss 162743 Compact ISO time
hh:mm:ss am/pm 4:27:43 PM US 12-hour time
hhmmss am/pm 042743 PM Compact US 12-hour time

Datetime formats can consist of any combination of the date and time formats above, separated by space, or a T in the case of ISO formats.

Leading zeroes may be omitted in days and months, and years may be specified with 2 digits in non-ISO formats, which will be interpreted in the range 1930-2029.

Seconds and minutes may be omitted in times, which will be interpreted as 0.

classmethod parse_date(date)

Parses a date in any supported format, and returns a tuple with year, month, and day.

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 a date and time in any supported format and returns a tuple with year, month, day, hour, minute, and second.

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 a time in any supported format and returns a tuple with hour, minutes, and seconds.

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

Previous topic

chrono.parser.Parser - Base class for parsers

Next topic

chrono.parser.EuroParser - Parser for european formats