4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/creative_rails_utilities/view_helpers.rb', line 4
def relative_time_parse(earlier_time, later_time=nil)
later_time ||= Time.now
difference = (later_time.to_i - earlier_time.to_i).to_i
case difference
when 0
return {key: "now", count: nil}
when 1
return {key: "second", count: nil}
when 2..59
return {key: "seconds", count: difference.to_s}
when 60..119
return {key: "minute", count: nil}
when 120..3540
return {key: "minutes", count: (difference/60).to_i.to_s}
when 3541..7100
return {key: "hour", count: nil}
when 7101..82800
return {key: "hours", count: ((difference+99)/3600).to_i.to_s}
when 82801..172000
return {key: "day", count: nil}
else
if difference < 0
return {key: "now", count: nil}
else
return {key: "days", count: ((difference+800)/(60*60*24)).to_i.to_s}
end
end
end
|