Skip to content

Keep original input for DateDelta #247

@aquarhead

Description

@aquarhead

Hi, we are currently looking into adopting this library in our Python backend to handle especially "Duration" in a sane way, however we soon discovered a rather unexpected behaviour where the DateDelta units are being converted.

After some digging we found this has been discussed in #110 however I don't agree with the points being made there. We are exposing these Durations as a core configuration to our users and it would be pretty bad UX if they input "3 weeks" and it always get converted into "21 days", and vice versa. In our use case, it's a lot better to use a specific time unit so that users can align their expectations and don't need to convert the units back and forth - if they configure the view to be weekly, it's much easier to compute "3 weeks later" instead of "21 days later" in ones head.

>>> from whenever import DateDelta
>>> DateDelta(months=36).format_common_iso()
'P3Y'
>>> DateDelta(weeks=3).format_common_iso()
'P21D'

And for reference this doesn't happen in jiff (where I was pointed to whenever for Python integration)

$ biff span iso8601 2y36months3w60d
P2Y36M3W60D

I was also wondering if the ISO8601 standard has anything to say on this matter, but couldn't find any reference, would be great to know if there is a standard on this.

I would like to open a discussion before maybe working on a PR, since I really only care about the immediate save then display case (i.e. parse+format returns the same data) I'm thinking one way to do it is to only keep track of "original years" and "original weeks" input, use them if nothing changed but ditch them as soon as any calculation is performed (when adding/subtracting, convert to months+days first).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussion is needed before proceeding

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions