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

Diff of /trunk/src/util.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by rakin, Mon Jul 29 17:28:11 2024 UTC revision 37 by rakin, Mon Jul 29 17:28:18 2024 UTC
# Line 1  Line 1 
1  module.exports = {  module.exports = {
2      escapeRegex(string) {      escapeRegex(string) {
3          return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');          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  };  };

Legend:
Removed from v.5  
changed lines
  Added in v.37

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26