On Dec 2, 1:58 pm, Daniel Waite <rabbitb... / gmail.com> wrote:
> First off, if there's already a method that does this please point it
> out; I couldn't find one so I wrote my own.
>
> It's currently called #to_elapsed_time and is attached to Fixnum. What
> it does...
>
> >> 10.to_elapsed_time
>
> => {:days=>0, :minutes=>0, :seconds=>10, :hours=>0}>> 75.to_elapsed_time
>
> => {:days=>0, :minutes=>1, :seconds=>15, :hours=>0}>> 75018.to_elapsed_time
>
> => {:days=>0, :minutes=>50, :seconds=>18, :hours=>20}>> 789010.to_elapsed_time
>
> => {:days=>9, :minutes=>10, :seconds=>10, :hours=>3}
>
> The current name makes sense to me because I wrote it with this in mind:
>
> started = Time.now
> ended = Time.now + some_time_into_the_future
> elapsed = (ended.to_i - started.to_i).to_elapsed_time
>
> Looking at it now I suppose I could attach it to Time, too...
>
> time_1.elapsed(time_2)
>
> That would be kinda cool, too.
>
> What do you think?
> --
> Posted viahttp://www.ruby-forum.com/.

You might want to take a look at the Duration gem: http://rubyforge.org/projects/duration/

It's very similar to what you have here.

HTH,
Chris