Forum: Ruby on Rails Formatting an expiring time in days, minutes and seconds

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Scott (Guest)
on 2007-03-15 06:21
(Received via mailing list)
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
(Guest)
on 2007-03-15 07:16
(Received via mailing list)
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/Help...

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
This topic is locked and can not be replied to.