Hi
I have an object which has an expiration date. I want to calculate the
amount of days, hrs and mins until the expiration time.
Does rails come with functions to do this? Also if the time has passed
i want it to say 0 days 0 hrs and 0 mins.
Does anyone know a quick way to do this?
rab
(Rob Biedenharn)
3
deadline = Time.mktime( 2007, 8, 22, 12, 0, 0, 0 )
=> Wed Aug 22 12:00:00 -0400 2007
secs = [ deadline - Time.now, 0 ].max ; \
"%dd %2d:%02d:%02d" % [ secs.to_i / 86400, (secs % 86400).to_i / 3600, *((secs % 3600).divmod(60)) ]
=> "0d 1:56:35"
And it sounds like you want to wrap this up in a method on that object so you can do something like:
e = Expiration.new(Time.mktime( 2007, 8, 22, 12, 0, 0, 0 ))
puts e.time_remaining
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Thats great. Thought they'd be something to use. Thanks