# [Python-Dev] dateutil

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Mar 15 19:32:06 EST 2004

```Gustavo Niemeyer <niemeyer at conectiva.com>:

> IMO, no. The "relative" here means that the operation made is dependent
> on what you apply it, and not a "fixed" delta as timedelta would do.

Hmmm. I see what you're getting at, but that interpretation goes
beyond what the word "relative" suggests to me. Maybe it makes sense
to you, but I think it's going to look confusing to anyone who doesn't

Moreover, the terms "relative" and "delta" and the use of the "+"
operator all suggest that these things form some kind of algebra,
which they clearly don't.

> > So a relativedelta can affect things in a way that's not
> > relative at all? That sounds *very* confusing.
>
> It makes sense in this context. Please, have a look at the examples
> in the documentation.

This seems to be a matter of opinion. I've looked at the examples, and
haven't seen anything to make me change my mind. I still think it's
nonsensical to have something called a "delta" that doesn't behave
algebraically when you add it to something.

> > So there is a hole at 0. Something about that smells wrong.
>
> If you discover what, please tell me. :-)

I think what it means is that you haven't got a single operation with
an integer parameter. Rather, you've got two different operations,
each of which has a natural number parameter, and you're using the
sign of the parameter to encode which operation you want.

Also, I don't understand why the "weeks" parameter isn't used to
adjust the number of weeks here, instead of supplying it in a rather
funky way as a kind of parameter to a parameter. In other words,

relativedelta(day = MO(+3))

why not

relativedelta(day = MO, weeks = +2)

which would make more sense to me.

> > I think the OP's question was what happens if you do
> >
> >   for i in range(12):
> >     d += relativedelta(months=+1)
>
> I answered that just below the above example. It lands on the same
> date.

In all cases? You mean that

d = datetime(2000, 1, 31)
for i in range(12):
d += relativedelta(months=+1)

will give the same result as

d = datetime(2000, 1, 31)
d += relativedelta(months=+12)

and/or

d = datetime(2000, 1, 31)
d += relativedelta(years=+1)

?

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+

```