Hi, I have an expiry date. I want to format it in such a way that it will read "Expires in x days, x hours and x minutes". Is there an easy way to do this with some of the date/time formatting of ruby? Thanks, Scott --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
andrew.ohnstad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-15 05:15 UTC
Re: Formatting an expiring time in days, minutes and seconds
Rails does have some built in methods to format time for humans. You might be interested in distance_of_time_in_words_to_now (or the shorter named, identical, less intuitive, time_ago_in_words). I''ve used them before with fine results, but you should read the API carefully... http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M000574 It doesn''t provide the level of detail you asked for in your post... it rounds up to "12 minutes ago" or once more than a month has passed, it goes to "about a month ago", "about 3 months ago" etc. It WILL get specific below 1 minute 29 seconds, but even for that you have to set an option. This was good enough for my needs, but might not be good enough for yours. I haven''t found an elegant way to get exact times. Good Luck and let me know if you do find something. ---A On Mar 15, 12:19 am, "Scott" <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have an expiry date. I want to format it in such a way that it will > read "Expires in x days, x hours and x minutes". Is there an easy way > to do this with some of the date/time formatting of ruby? > > Thanks, > > Scott--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---