31 lines
654 B
JavaScript
31 lines
654 B
JavaScript
function pad(value) {
|
|
return String(value).padStart(2, "0");
|
|
}
|
|
|
|
function formatCountdown(totalSeconds) {
|
|
const safe = Math.max(0, Math.floor(totalSeconds || 0));
|
|
const minutes = Math.floor(safe / 60);
|
|
const seconds = safe % 60;
|
|
return `${pad(minutes)}:${pad(seconds)}`;
|
|
}
|
|
|
|
function formatTime(timestamp) {
|
|
const date = new Date(timestamp);
|
|
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
}
|
|
|
|
function randomCode() {
|
|
return String(Math.floor(100000 + Math.random() * 900000));
|
|
}
|
|
|
|
function clone(value) {
|
|
return JSON.parse(JSON.stringify(value));
|
|
}
|
|
|
|
module.exports = {
|
|
formatCountdown,
|
|
formatTime,
|
|
randomCode,
|
|
clone
|
|
};
|