/[sudobot]/trunk/src/util.js
ViewVC logotype

Contents of /trunk/src/util.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations)
Mon Jul 29 17:28:19 2024 UTC (8 months ago) by rakin
File MIME type: text/javascript
File size: 1229 byte(s)
Improved edited message scanning and added file filters
1 module.exports = {
2 escapeRegex(string) {
3 return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
4 },
5 timeSince(date) {
6 const seconds = Math.floor((Date.now() - date) / 1000);
7 let interval = seconds / (60 * 60 * 24 * 30 * 365);
8
9 if (interval >= 1) {
10 return Math.floor(interval) + " year" + (Math.floor(interval) === 1 ? '' : 's');
11 }
12
13 interval = seconds / (60 * 60 * 24 * 30);
14
15 if (interval >= 1) {
16 return Math.floor(interval) + " month" + (Math.floor(interval) === 1 ? '' : 's');
17 }
18
19 interval = seconds / (60 * 60 * 24);
20
21 if (interval >= 1) {
22 return Math.floor(interval) + " day" + (Math.floor(interval) === 1 ? '' : 's');
23 }
24
25 interval = seconds / (60 * 60);
26
27 if (interval >= 1) {
28 return Math.floor(interval) + " hour" + (Math.floor(interval) === 1 ? '' : 's');
29 }
30
31 interval = seconds / 60;
32
33 if (interval >= 1) {
34 return Math.floor(interval) + " minute" + (Math.floor(interval) === 1 ? '' : 's');
35 }
36
37 interval = seconds;
38
39 return Math.floor(interval) + " second" + (Math.floor(interval) === 1 ? '' : 's');
40 }
41 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26