3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/orange-more/pages/resources/page_resource.rb', line 3
def fuzzy_time(from_time)
to_time = Time.new
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
distance_in_minutes = (((to_time - from_time).abs)/60).round
distance_in_seconds = ((to_time - from_time).abs).round
case distance_in_minutes
when 0..1
return distance_in_minutes == 0 ? "Less than 1 minute ago" : "About 1 minute ago"
when 2..44 then "#{distance_in_minutes} minutes ago"
when 45..89 then "An hour ago"
when 90..1439 then "#{(distance_in_minutes.to_f / 60.0).round} hours ago"
when 1440..2879 then "Yesterday"
when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
when 43200..86399 then "1 Month ago"
when 86400..525599 then "#{(distance_in_minutes / 43200).round} months ago"
when 525600..1051199 then "1 year ago"
else "Over #{(distance_in_minutes / 525600).round} years ago"
end
end
|