[ANN] python-dateutil 0.1
Gustavo Niemeyer
niemeyer at conectiva.com
Thu Oct 9 09:27:30 EDT 2003
> >What is it?
> >-----------
> >The dateutil module provides powerful extensions to the standard
> >datetime module, available in Python 2.3+.
> >
> .... is there support for business dates ie number of business days
> between two dates etc?
It will be hard to find something you can't do. :-)
How may work days until the end of the month?
>>> from dateutil.rrule import *
>>> from datetime import *
>>> now = datetime.now()
>>> len(list(rrule(FREQ_DAILY,byweekday=(MO,TU,WE,TH,FR),
dtstart=now,until=now.replace(day=31))))
16
Hummm.. interesting enough, this result is not right. Today should
also be counted in this case. There's a small bug related to
micrseconds handling in the module: since the recurrence is compared
against a date without microseconds, the recurrence is not greater
than the dtstart passed. I haven't got this because all 415 testcases
were using datetime instances without microseconds. Well, we
have 417 now.. ;-)
Here is the right result, with the fix:
>>> len(list(rrule(FREQ_DAILY,byweekday=(MO,TU,WE,TH,FR),
dtstart=now,until=now.replace(day=31))))
17
Thanks!
--
Gustavo Niemeyer
http://niemeyer.net
More information about the Python-list
mailing list