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

string output #24

Open smcabrera opened 9 years ago

smcabrera commented 9 years ago

Currently outputting as a string gives you the following:

Duration.new(1000).to_s
=> "#<Duration:0x007fc7f28f5ce8>"

I'd love to implement a to_s function that would cause durations to output a little more like the way the Time class works:

Time.new.to_s
=> "2015-03-02 17:59:27 -0500"

Something like this:

Duration.new(1000).to_s
=> "00:16:40"

The only issue I can think of is that you allow for days and weeks and I'm not sure what format those should be outputted in...thoughts?

lacostenycoder commented 5 years ago

We already have a problem that this gem doesn't correctly support ISO 8061 Duration, for example calling this method should return the same value as the input but it doesn't.

irb(main):004:0>  d = Duration.new('P3Y6M4DT12H30M5S')
=> #<Duration:0x007fdb4ea67df0 @seconds=5, @negative=false, @total=110766605, @weeks=183, @days=1, @hours=0, @minutes=30>
irb(main):005:0> d.iso8601
=> "P1282DT30M5S"