[Python-Dev] dateutil
Robert Brewer
fumanchu at amor.org
Thu Mar 11 16:31:28 EST 2004
Skip Montanaro wrote:
> I'd like to try out your natural language parser, but can't
> find it. I
> naively thought this might work, but it doesn't:
>
> >>> import recur
> >>> import datetime
> >>> for eachDate in recur.Recurrence(datetime.date(2004,
> 1, 7), "every 4 days", datetime.date(2004, 4, 15)):
> ... print eachDate
> ...
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "recur.py", line 599, in __init__
> raise ValueError, (u"The supplied description ('%s') "
> ValueError: The supplied description ('every 4 days')
> could not be parsed.
In this case, use:
>>> import recur
>>> import datetime
>>> for eachDate in recur.Recurrence(datetime.date(2004, 1, 7), "4
days", datetime.date(2004, 4, 15)):
... print eachDate
...
2004-01-07
2004-01-11
2004-01-15
2004-01-19
2004-01-23
2004-01-27
2004-01-31
2004-02-04
2004-02-08
2004-02-12
2004-02-16
2004-02-20
2004-02-24
2004-02-28
2004-03-03
2004-03-07
2004-03-11
2004-03-15
2004-03-19
2004-03-23
2004-03-27
2004-03-31
2004-04-04
2004-04-08
2004-04-12
It would be a simple thing to fix by changing a regex in
Locale.patterns[byunits] from r"([0-9]+) days?" to r"(?:every )?([0-9]+)
days?" I'll probably add this to my default Locale class, but one of
the reasons I made a separate Locale class in the first place was to
facilitate such modification via subclassing.
> I realize this is a usage question and python-dev isn't a usage list.
> Still, it suggests that perhaps the community as a whole
> needs a bit more
> exposure to these concepts before they are incorporated into
> the standard
> library. Perhaps a PEP about recurrence relations is warranted.
As Gustavo has pointed out, the internal, representational details have
been pretty much nailed in the iCal RFC. But I agree with you that
wrapping them for locale-specific, end-user ease-of-use is important. I
wouldn't worry about a PEP unless DateUtil approaches Library inclusion
status.
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-Dev
mailing list