ISO 8601 duration and dateutil.relativedelta.relativedelta

Issue #6 resolved
Sébastien Celles created an issue

Hello,

aniso8601.parse_duration should be able to return a dateutil.relativedelta.relativedelta from a duration ISO 8601 string (because years don't have always 365 days and months 30 days)

see also https://bugs.launchpad.net/dateutil/+bug/1507735

Kind regards

Comments (7)

  1. Sébastien Celles reporter

    If you don't want to use dateutil an other approach could be to use Pandas DateOffset like

    import pandas as pd
    pd.tseries.offsets.DateOffset(years=2, months=6, days=1)
    
  2. Brandon Nielsen repo owner

    Interesting, dateutil provides an easy way to provide calendar level accuracy to both parse_duration and parse_interval.

    I've branched 1.1.0 dev and added a 'relative' keyword argument to both parse_duration and parse_interval. When relative=False, the old behavior is used (a year is 365 days, a month is 30 days), when relative=True, dateutil.relativedelta is used, allowing proper calendar accuracy where possible. README has been updated accordingly.

    Is that what you had in mind? If yes, I can tag and release v.1.1.0 to PyPI.

  3. Sébastien Celles reporter

    I don't know exactly what is the best approach between Pandas DateOffset and dateutil.relativedelta. But I like how you did this.

  4. Brandon Nielsen repo owner

    Pandas is much too large of a dependency (3+ megs) to introduce into a small library like this. dateutil adds nice calendar correct functionality with a comparatively small size (~200 k).

    dateutil relativedelta support is included in v1.1.0, which has been released on PyPI. It functions as described in the above comment.

    Marking this done.

  5. Log in to comment