[Python-Dev] dateutil

Gustavo Niemeyer niemeyer at conectiva.com
Thu Mar 11 16:59:16 EST 2004


> Before I give my vote on DateUtil I know I would love to hear Gustavo 
> give a quick comparison to datetime in terms of what DateUtil provides 
> over datetime.  For instance, as Tim showed above (I should have known 
> there was a better way with datetime than with my nutty way of doing 
> it), datetime supports time deltas.  So why should we use DateUtil's or 
> what should we try to take from it?  Same for parser (compared to 
> strptime) and tz (compared to tzinfo).  I could obviously stare at the 
> wiki and datetime docs, but I am sure Gustavo can give a better overview 
> than I could glean on my own.

Here is a quick list of features, from the website:

* Computing of relative deltas (next month, next year,
  next monday, last week of month, and a lot more);

* Computing of relative deltas between two given
  date and/or datetime objects;

* Computing of dates based on very flexible recurrence rules
  (every month, every week on Thursday and Friday, every
  Friday 13th, and a *LOT* more), using a superset of the
  iCalendar RFC 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.

Please, check the website for complete documentation:

https://moin.conectiva.com.br/DateUtil

> The rrule idea does sound cool and could be neat to add to datetime.  I 
> can see having an iterator for these things being useful to someone 
> (unless I am making myself partially look like a fool again by having 
> this be in datetime already without me realizing it).

Btw, here is a fun task for rrule:

Every four years, the first Tuesday after a Monday in November, 3
occurrences (U.S. Presidential Election day): 

>>> list(rrule(FREQ_YEARLY, interval=4, count=3, bymonth=11,
               byweekday=TU, bymonthday=(2,3,4,5,6,7,8),
               dtstart=parse("19961105T090000")))
[datetime.datetime(1996, 11, 5, 9, 0),
 datetime.datetime(2000, 11, 7, 9, 0),
 datetime.datetime(2004, 11, 2, 9, 0)]

-- 
Gustavo Niemeyer
http://niemeyer.net



More information about the Python-Dev mailing list