mirror of
https://github.com/zoriya/flood.git
synced 2026-06-02 19:11:14 +00:00
Move eta function to shared format utility
This commit is contained in:
@@ -1,7 +1,33 @@
|
||||
'use strict';
|
||||
let moment = require('moment');
|
||||
|
||||
const FORMAT_UTIL = {
|
||||
const formatUtil = {
|
||||
secondsToDuration: cumSeconds => {
|
||||
const years = Math.floor(cumSeconds / 31536000);
|
||||
const weeks = Math.floor((cumSeconds % 31536000) / 604800);
|
||||
const days = Math.floor(((cumSeconds % 31536000) % 604800) / 86400);
|
||||
const hours = Math.floor((((cumSeconds % 31536000) % 604800) % 86400) / 3600);
|
||||
const minutes = Math.floor(((((cumSeconds % 31536000) % 604800) % 86400) % 3600) / 60);
|
||||
const seconds = Math.floor(cumSeconds - (minutes * 60));
|
||||
let timeRemaining = null;
|
||||
|
||||
if (years > 0) {
|
||||
timeRemaining = {years, weeks, cumSeconds};
|
||||
} else if (weeks > 0) {
|
||||
timeRemaining = {weeks, days, cumSeconds};
|
||||
} else if (days > 0) {
|
||||
timeRemaining = {days, hours, cumSeconds};
|
||||
} else if (hours > 0) {
|
||||
timeRemaining = {hours, minutes, cumSeconds};
|
||||
} else if (minutes > 0) {
|
||||
timeRemaining = {minutes, seconds, cumSeconds};
|
||||
} else {
|
||||
timeRemaining = {seconds, cumSeconds};
|
||||
}
|
||||
|
||||
return timeRemaining;
|
||||
},
|
||||
|
||||
minToHumanReadable: min => {
|
||||
return moment.duration(min * 60 * 1000).humanize();
|
||||
},
|
||||
@@ -45,4 +71,4 @@ const FORMAT_UTIL = {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FORMAT_UTIL;
|
||||
module.exports = formatUtil;
|
||||
|
||||
Reference in New Issue
Block a user