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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26