How to form “fuzzy date” in Ruby?


How to form “fuzzy date” in Ruby?



How do I form "fuzzy" date/time from RFC 2822 formatted (Sat, 18 Jul 2009 10:57:43 +0300) timestamp?

With fuzzy date I mean like: "5 minutes ago", "2 days, 15 minutes ago".




.NET Greenwich Mean Time

1:



Format DateTime in Text Box in Rails
Rails gives your views a helper function called time_ago_in_words that you can call to output just such a format from a Time object..
Finding if a python datetime has no time information


Adding certain minutes to time in MySQL


Performing Date/Time Math In HQL?

2:



Using DateTime.TryParseExact to verify XML Schema dateTime compliance
def fuzzy_date(date)   date = Date.parse(date, true) unless /Date.*/ =~ date.class.to_s   days = (date - Date.today).to_i   return 'today'     if days >= 0 and days < 1   return 'tomorrow'  if days >= 1 and days < 2   return 'yesterday' if days >= -1 and days < 0   return "in #{days} days"      if days.abs < 60 and days > 0   return "#{days.abs} days ago" if days.abs < 60 and days < 0   return date.strftime('%A, %B %e') if days.abs < 182   return date.strftime('%A, %B %e, %Y') end 


Multiple rows selected from a date ranged row


C# Date Parse Exact mindate issues

3:


There's some really powerful date/time parsers in ruby (unfortunately kind of hard to google(TM) for). http://chronic.rubyforge.org/. http://www.ahabman.com/blog/2009/06/ruby-duration/. http://github.com/flogic/timely/tree/master.



85 out of 100 based on 65 user ratings 1315 reviews