[Python-Dev] dateutil
Christian Tanzer
tanzer at swing.co.at
Tue Mar 16 01:44:37 EST 2004
> > > Supporting this might be cool indeed. OTOH, it doesn't replace the
> > > current behavior. How do you get (day=30)?
> >
> > I don't follow. The semantics would be similar to list indexing.
> >
> > `day=30` asks for the 30-est day of the month and raises an ValueError
> > if there isn't any. `day=-1` asks for the last day of the month (and
> > should never raise an error <wink>).
>
> What advantage do you get with the raised error? The replace() method
> of dateutil already does something similar, and I'm not trying to
> mimic it.
IMHO, it is more useful if the caller specifies the exact intent and
gets what he asks for. Being able to pass any positive large number
and get the last day of the month doesn't look like a good interface
to me.
> I'm trying to provide some aditionally useful mechanism.
I'm glad you do. Thank you.
> > The allowed argument range for `day` would be between 1 and `n` with
> > `n` the number of days in the month for positive values and between -1
> > and `-n` for negative values.
>
> The whole point of being relative is that it acts differently on
> different dates. What happens when you do
>
> date(2004, 1, 31) + relativedelta(months=1)
>
> Will it raise an error as well? The current behavior is consistently
> designed to get useful results, in addition to what datetime provides.
I don't know. The problem here is that it is not obvious what is going
to happen. Consider:
d1 = date(2004, 1, 31)
d2 = date(2004, 1, 28)
d1_1 = d1 + relativedelta(months=1)
d2_1 = d2 + relativedelta(months=1)
If you subscribe to d1_1 == d2_1, what do you expect to be the result
of:
d1_1 + relativedelta(months=1)
d2_1 + relativedelta(months=1)
Whatever you choose it will be seriously inconsistent from one point
of view or another.
--
Christian Tanzer http://www.c-tanzer.at/
More information about the Python-Dev
mailing list