1 |
rakin |
49 |
function timeProcess(seconds) { |
2 |
|
|
let interval = seconds / (60 * 60 * 24 * 30 * 365); |
3 |
rakin |
37 |
|
4 |
rakin |
49 |
if (interval >= 1) { |
5 |
|
|
return Math.floor(interval) + " year" + (Math.floor(interval) === 1 ? '' : 's'); |
6 |
|
|
} |
7 |
rakin |
37 |
|
8 |
rakin |
49 |
interval = seconds / (60 * 60 * 24 * 30); |
9 |
rakin |
37 |
|
10 |
rakin |
49 |
if (interval >= 1) { |
11 |
|
|
return Math.floor(interval) + " month" + (Math.floor(interval) === 1 ? '' : 's'); |
12 |
|
|
} |
13 |
rakin |
37 |
|
14 |
rakin |
49 |
interval = seconds / (60 * 60 * 24); |
15 |
rakin |
37 |
|
16 |
rakin |
49 |
if (interval >= 1) { |
17 |
|
|
return Math.floor(interval) + " day" + (Math.floor(interval) === 1 ? '' : 's'); |
18 |
|
|
} |
19 |
rakin |
37 |
|
20 |
rakin |
49 |
interval = seconds / (60 * 60); |
21 |
rakin |
37 |
|
22 |
rakin |
49 |
if (interval >= 1) { |
23 |
|
|
return Math.floor(interval) + " hour" + (Math.floor(interval) === 1 ? '' : 's'); |
24 |
|
|
} |
25 |
rakin |
37 |
|
26 |
rakin |
49 |
interval = seconds / 60; |
27 |
rakin |
37 |
|
28 |
rakin |
49 |
if (interval >= 1) { |
29 |
|
|
return Math.floor(interval) + " minute" + (Math.floor(interval) === 1 ? '' : 's'); |
30 |
|
|
} |
31 |
rakin |
37 |
|
32 |
rakin |
49 |
interval = seconds; |
33 |
|
|
|
34 |
|
|
return Math.floor(interval) + " second" + (Math.floor(interval) === 1 ? '' : 's'); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
module.exports = { |
38 |
|
|
escapeRegex(string) { |
39 |
|
|
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); |
40 |
|
|
}, |
41 |
|
|
timeSince(date) { |
42 |
|
|
const seconds = Math.floor((Date.now() - date) / 1000); |
43 |
|
|
return timeProcess(seconds) + ' ago'; |
44 |
|
|
}, |
45 |
|
|
timeProcess |
46 |
rakin |
5 |
}; |