Representing time differences in Ruby -


Is Ruby stadilib have an object that represents the difference between two timestamps? Returns a float number second by subtracting two time objects from each other - for this there is any object, such as hours , minutes etc. , And the most decent to_s

I've coded a half-ass approach for too long, am I doing it wrong?

Not in stdlib, but a gem that you can use for the job - gem.

  sudo gem install period  

You can use it like this:

  "duration" required = A.nleep.Now sleep (5) b = time.non period duration.new (b - a) # = & gt; # & Lt; Duration: 5 seconds & gt; Period .seconds # = & gt; 5 period Min # = & gt; 0  

and a bunch of days, hours, weeks, and other useful methods.

If you still have monkey-patch time, date and other time-to-time classes return period items.


Comments