| 456 | } |
| 457 | |
| 458 | function formatSeconds(sec, keepAll = false) { |
| 459 | if (FormatCache.has(sec)) return FormatCache.get(sec); |
| 460 | let days = Math.floor(sec / 86400); |
| 461 | let hours = Math.floor((sec % 86400) / 3600); |
| 462 | let minutes = Math.floor((sec % 3600) / 60); |
| 463 | let seconds = Math.floor(sec % 60); |
| 464 | |
| 465 | let result = ""; |
| 466 | let arr = [ |
| 467 | [days, "d"], |
| 468 | [hours, "h"], |
| 469 | [minutes, "m"], |
| 470 | [seconds, "s"], |
| 471 | ]; |
| 472 | arr.forEach(([value, unit], index) => { |
| 473 | if (value > 0 || keepAll) { |
| 474 | if (value < 10) value = "0" + value; |
| 475 | result += `${value}${unit}`; |
| 476 | if (index < arr.length - 1) result += " "; |
| 477 | } |
| 478 | }); |
| 479 | FormatCache.set(sec, result); |
| 480 | return result; |
| 481 | } |
| 482 | |
| 483 | function formatDate(date) { |
| 484 | let year = date.getFullYear(); |