add duration

This commit is contained in:
Romulus21
2024-02-17 00:02:39 +01:00
parent 335fc8b12b
commit f27ffc1ce8
19 changed files with 248 additions and 48 deletions

View File

@@ -1,12 +1,31 @@
interface Number {
pad(n: number, char?: string): string
pad(n: number, char?: string): string,
durationify(): string
}
Number.prototype.pad = function(n, char = "0") {
return (new Array(n).join(char) + this).slice(-n)
}
Number.prototype.durationify = function () {
if (! this) {
return '0s'
}
const base = Number(this)
const days = Math.floor(base / 60 / 60 / 24)
const hours = Math.floor((base - (days * 60 * 60 * 24)) / 60 / 60)
const minutes = Math.floor((base - (days * 60 * 60 * 24) - (hours * 60 *60)) / 60)
const secondes = Math.floor(base - (days * 60 * 60 * 24) - (hours * 60 *60) - (minutes *60))
let duration = ''
duration += (days) ? `${days}j ` : ''
duration += (days > 0 || hours > 0) ? `${hours}h ` : ''
duration += (days > 0 || hours > 0 || minutes > 0) ? `${minutes}m ` : ''
duration += `${secondes}s`
return duration
}
interface Date {
toFrDate(): string,
toFrTime(): string,
@@ -27,6 +46,10 @@ Date.prototype.toSmallFrDate = function() {
return `${this.toFrTime()}`
}
if ((new Date(this)).getFullYear() === (new Date()).getFullYear()) {
return `${this.getDate()}/${Number(this.getMonth() + 1).pad(2)} ${this.toFrTime()}`
}
return `${this.toFrDate()} ${this.toFrTime()}`
}