pendulum
pendulum copied to clipboard
Add Duration.to_iso8601_string()
Add a Duration.to_iso8601_string()
method to output a standalone duration as an ISO8601 string.
Fixes #306
Still some work in progress:
- Need to handle negative duration values
- Add tests for negative durations
I have yet to find any info on whether the standard allows for durations like P10M-1D
(which seems like it could be useful).
Haven't purchased the standard, so not sure if present in the full standard.
This has a BNF, but doesn't define week
, hour
, month
in it so no help there.
https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0039_iso_wd_8601-2_2016-02-16.pdf
Not too sure what's happening with the failing tests. I'll have a look at it in a bit, but am not too familiar with pypy or python 2.7, so would appreciate any thoughts.
Turns out the bug was caused by round returning a float instead of an int in python2, so duration.__init__()
was saving microseconds as a float.
@sdispater I'm still not sure how/if negative durations should be handled, but this should otherwise be good to go.
I.e. Would "P1M-1D" or "-P5D" be valid ISO8601 duration strings?
I don't have the full standard, but what I've seen doesn't mention whether negative durations or duration components are possible.
Looks like Moment.js has encountered similar: https://github.com/moment/moment/issues/2408 https://github.com/moment/moment/pull/2955
How should I proceed? Happy to add support for negative durations if you'd like.
Hi @sdispater, I would appreciate your thoughts if you have a chance.
Have been looking for this. Would be very useful.
I've also stumbled upon this as a nice-to-have feature
I just bumped into this, would really appreciate it getting merged soon!
If there's any help I can add, testing/debugging etc. please shout.
Thanks from the bumps, just waiting on some input from @sdispater or another authority on how negative durations should be handled. There's a few other PRs pending, so happy to fix any conflicts if you'd like to accept other PRs first
Nice work! Would love to have this feature available!
is this going to be released?
I'm still waiting on a response and some input from @sdispater Happy to rebase and fix conflicts after that.
Any update on this?
Not from my end :slightly_smiling_face:
Would also love to see this. It sounds like there isn't work needed other than decision on negative timestamps? @sdispater is this under consideration?