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

Annotation of /trunk/src/util.js

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26