react-progress-timer
Version:
This react component will automatically calculate the time to complete a progress bar by percentage changing speed.
33 lines (28 loc) • 990 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _default = function _default(milliseconds, percentage, format) {
var seconds = Math.ceil(milliseconds / 1000);
var unit = "second(s)";
var timeValue = seconds;
if (seconds > 12 * 30 * 24 * 60 * 60) {
timeValue = timeValue / (12 * 30 * 24 * 60 * 60);
unit = "year(s)";
} else if (seconds > 30 * 24 * 60 * 60) {
timeValue = timeValue / (30 * 24 * 60 * 60);
unit = "month(s)";
} else if (seconds > 24 * 60 * 60) {
timeValue = timeValue / (24 * 60 * 60);
unit = "day(s)";
} else if (seconds > 60 * 60) {
timeValue = timeValue / (60 * 60);
unit = "hour(s)";
} else if (seconds > 60) {
timeValue = timeValue / 60;
unit = "minute(s)";
}
return format.replace("{value}", Math.ceil(timeValue).toString()).replace("{unit}", unit).replace("{percentage}", Math.round(percentage).toString());
};
exports["default"] = _default;
;