/[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 49 by rakin, Mon Jul 29 17:28:21 2024 UTC
# Line 1  Line 1 
1    function timeProcess(seconds) {      
2        let interval = seconds / (60 * 60 * 24 * 30 * 365);
3    
4        if (interval >= 1) {
5            return Math.floor(interval) + " year" + (Math.floor(interval) === 1 ? '' : 's');
6        }
7    
8        interval = seconds / (60 * 60 * 24 * 30);
9    
10        if (interval >= 1) {
11            return Math.floor(interval) + " month" + (Math.floor(interval) === 1 ? '' : 's');
12        }
13    
14        interval = seconds / (60 * 60 * 24);
15    
16        if (interval >= 1) {
17            return Math.floor(interval) + " day" + (Math.floor(interval) === 1 ? '' : 's');
18        }
19    
20        interval = seconds / (60 * 60);
21    
22        if (interval >= 1) {
23            return Math.floor(interval) + " hour" + (Math.floor(interval) === 1 ? '' : 's');
24        }
25    
26        interval = seconds / 60;
27    
28        if (interval >= 1) {
29            return Math.floor(interval) + " minute" + (Math.floor(interval) === 1 ? '' : 's');
30        }
31    
32        interval = seconds;
33    
34        return Math.floor(interval) + " second" + (Math.floor(interval) === 1 ? '' : 's');
35    }
36    
37  module.exports = {  module.exports = {
38      escapeRegex(string) {      escapeRegex(string) {
39          return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');          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  };  };

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26