10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/friendly_time.rb', line 10
def self.friendly_time(from_time, to_time)
timeInSecs = (from_time - to_time) / 1000
if timeInSecs.abs < @one_minute_in_seconds
if timeInSecs > 0
"seconds ago"
else
"in less than a minute"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 2
if timeInSecs > 0
"about a minute ago"
else
"in about a minute"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 10
if timeInSecs > 0
"minutes ago"
else
"in a few minutes"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 15
if timeInSecs > 0
"about 10 minutes ago"
else
"in about 10 minutes"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 20
if timeInSecs > 0
"about 15 minutes ago"
else
"in about 15 minutes"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 25
if timeInSecs > 0
"about 20 minutes ago"
else
"in about 20 minutes"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 30
if timeInSecs > 0
"about 25 minutes ago"
else
"in about 25 minutes"
end
elsif timeInSecs.abs < @one_minute_in_seconds * 45
if timeInSecs > 0
"about half an hour ago"
else
"in about half an hour"
end
elsif timeInSecs.abs < @one_hour_in_seconds
if timeInSecs > 0
"about 45 minutes ago"
else
"in about 45 minutes"
end
elsif timeInSecs.abs < @one_hour_in_seconds * 2
if timeInSecs > 0
"about an hour ago"
else
"in about an hour"
end
elsif timeInSecs.abs < @one_hour_in_seconds * 3
if timeInSecs > 0
"a couple of hours ago"
else
"in a couple of hours"
end
elsif timeInSecs.abs < @one_hour_in_seconds * 12
if timeInSecs > 0
"a few hours ago"
else
"in a few hours"
end
elsif timeInSecs.abs < @one_hour_in_seconds * 18
if timeInSecs > 0
"about 12 hours ago"
else
"in about 12 hours"
end
elsif timeInSecs.abs < @one_day_in_seconds
if timeInSecs > 0
"about 18 hours ago"
else
"in about 18 hours"
end
elsif timeInSecs.abs < @one_day_in_seconds * 2
if timeInSecs > 0
"yesterday"
else
"tomorrow"
end
elsif timeInSecs.abs < @one_day_in_seconds * 3
if timeInSecs > 0
"a couple of days ago"
else
"in a couple of days"
end
elsif timeInSecs.abs < @one_week_in_seconds
if timeInSecs > 0
"days ago"
else
"in a few days"
end
elsif timeInSecs.abs < @one_week_in_seconds * 2
if timeInSecs > 0
"about a week ago"
else
"in about a week"
end
elsif timeInSecs.abs < @one_week_in_seconds * 3
if timeInSecs > 0
"a couple of weeks ago"
else
"in a couple of weeks"
end
elsif timeInSecs.abs < @one_month_in_seconds * 2
if timeInSecs > 0
"weeks ago"
else
"in a few weeks"
end
elsif timeInSecs.abs < @one_year_in_seconds
if timeInSecs > 0
"months ago"
else
"in a few months"
end
elsif timeInSecs.abs < @one_year_in_seconds * 2
if timeInSecs > 0
"about a year ago"
else
"in about a year"
end
elsif timeInSecs.abs < @one_year_in_seconds * 3
if timeInSecs > 0
"a couple of years ago"
else
"in a couple of years"
end
elsif timeInSecs > 0
"years ago"
else
"years from now"
end
end
|