I’m a little late here, since python-dateutil was released last week. Anyway, this is a Python package providing powerful extensions to the standard python datetime module, available with Python 2.3. I wrote it because I really missed some generic date/time manipulation features to empower the nice datetime module. I confess it ended up being a little more than what I expected initially, mainly because I had a lot of fun building these algorithms.
Here is a list of features, from the homepage:
- Computing of relative deltas (next month, next year, next monday, last week of month, etc);
- Computing of relative deltas between two given date and/or datetime objects;
- Computing of dates based on very flexible recurrence rules, using a superset of the iCalendar specification. Parsing of RFC strings is supported as well.
- Generic parsing of dates in almost any string format;
- Timezone (tzinfo) implementations for tzfile(5) format files (/etc/localtime, /usr/share/zoneinfo, etc), TZ environment string (in all known formats), iCalendar format files, given ranges (with help from relative deltas), local machine timezone, fixed offset timezone, and UTC timezone.
- Computing of Easter Sunday dates for any given year, using Western, Orthodox or Julian algorithms;
- More than 400 test cases.
And to give a small example, in addition to the many examples available in the web page, suppose I wanted to know the date of the three following company happy-hours, knowing that we have it once every month, in the last friday:
>>> from dateutil.rrule import * >>> rrule(FREQ_MONTHLY, count=3, byweekday=FR(-1))[:] [datetime.datetime(2003, 10, 31, 10, 37, 59), datetime.datetime(2003, 11, 28, 10, 37, 59), datetime.datetime(2003, 12, 26, 10, 37, 59)]
What about the next Friday 13th?
>>> from dateutil.rrule import * >>> rrule(FREQ_MONTHLY, bymonthday=13, byweekday=FR)[0] datetime.datetime(2004, 2, 13, 10, 42, 27)
Cool, isn’t it? :-)