gweis/isodate — pull request #2 by stefanor (2012-11-29 12:32:54+00:00)
Title: Fractional duration

I ran into a test failure when porting a private codebase to Python 2.7.

We were doing:

```python
import isodate, datetime
NOW = datetime.datetime.now()
P1Y = isodate.parse_duration("P1Y")
print P1Y + NOW
```

Under Python 2.6, this returns a `DeprecationWarning`:

```
site-packages/isodate/duration.py:173: DeprecationWarning: integer argument expected, got float
newdt = other.replace(year=newyear, month=newmonth, day=newday)
```

Under Python 2.7, it throws a `TypeError`:

```
Traceback (most recent call last):
File "", line 1, in
File "site-packages/isodate/duration.py", line 173, in __radd__
newdt = other.replace(year=newyear, month=newmonth, day=newday)
TypeError: integer argument expected, got float
```

Here are some patches, that add test coverage in this area, and avoid using floats in `Duration`s when possible.

However, a fractional `Duration` will still not be able to be used in arithmetic with a `datetime`/`date`. This could be fixed by transforming it into an integral `Duration`, at parse time. But that would come with a loss of information.

What does `P0.5M` actually mean? Is it equivalent to `P15D`? What about `P0.0001M`? Reading ISO8601 didn't give me much insight...

So, I'm ignoring fractional `Duration`s for now, unless you can suggest a good way forward.

Oh, it also occurs to me that using `Decimal` objects may be preferable to `float`s here.