A Python module for simple and convenient date/time handling, including parsing, arithmetic, comparison, formatting, and calendar functionality. It supports both the ISO and US calendars, and dates/times in ISO, US, and european formats.
2010-03-08: Version 0.3.0 released
This release adds support for date differences (intervals), julian day numbers, and constants for setting the default calendar and parser. It also fixes some errors in the documentation code examples.
2010-02-06: Version 0.2.0 released
This release adds support for US and european date formats, as well as the US calendar and 12-hour clocks. It also fixes formatting of 12-hour times.
python-chrono only requires a recent version of Python installed. It has been tested on Python versions 2.6 and 3.1, but should work on version 2.5 as well.
To install from a source distribution, simply run the usual setup.py script as root:
The documentation is available online, and is also distributed along with the module itself, in the archives available for download above.
Below are some simple examples of python-chrono usage. For more information see the python-chrono documentation, which also includes a more in-depth usage introduction.
>>> import chrono >>> # parse a date from an ISO date string >>> date = chrono.Date("2010-07-23") >>> >>> # get date parts >>> date.year 2010 >>> date.month 7 >>> date.day 23 >>> date.get() (2010, 7, 23) >>> >>> # do some simple arithetic >>> date.month += 6 >>> date.day += 14 >>> date.get() (2011, 2, 6) >>> >>> # format the date >>> date.format("$weekdayname $day. $monthname $year") 'Sunday 6. February 2011' >>> >>> # get some calendar information about the date >>> date.week() (2011, 5) >>> date.leapyear() False >>> date.monthdays() 28 >>> >>> # compare date with other dates, even as other datatypes like strings >>> date > chrono.Date("2011-01-01") True >>> date <= "2011-07-01" True >>> date == time.localtime() False