josedonizetti / ruby-duration

Immutable type that represents some amount of time with accuracy in seconds.
http://bit.ly/ruby-duration
MIT License
124 stars 23 forks source link

Add ability to parse iso8601 durations. #7

Closed joevandyk closed 11 years ago

joevandyk commented 12 years ago
Duration.new("P1M1DT1M1S")
 => #<Duration:0x007ff9428efd30 @seconds=1, @total=2714461, @weeks=4, @days=3, @hours=10, @minutes=1> 

I'm not an ISO8601 expert, but it appears many implementations ignore weeks in the format string. The Ruby iso8601 library does, and postgresql does as well:

select interval '1w';
 interval
----------
 P7D

In order to better operate with those libraries, this library no longer includes the week in the iso8601 format.

joevandyk commented 12 years ago

Actually according to wikipedia http://en.wikipedia.org/wiki/ISO_8601#Durations "Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W".

Note that there's no [n]W in the longer version. So I think that should be removed from the iso8601 output.

jrochkind commented 12 years ago

I'm interested in built-in ability to parse ISO8601 durations. Does committer plan to accept this pull request?

gcirne commented 11 years ago

Hi,

Sorry for the (really) long delay. Do you mind rebasing against current master?

joevandyk commented 11 years ago

Why'd this get closed?

joevandyk commented 11 years ago

New pull request here: #13