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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html Iain Adams wrote:> 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? > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 22, 2007, at 9:46 AM, William Pratt wrote:> http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html > http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html > http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html > > Iain Adams wrote: >> 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? > > -- > Sincerely, > > William Prattdeadline = 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-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thats great. Thought they''d be something to use. Thanks On 22 Aug, 14:46, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.htmlhttp://stdlib.rubyonrails.org/libdoc/date/rdoc/index.htmlhttp://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html > > Iain Adams wrote: > > 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? > > -- > Sincerely, > > William Pratt--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---