add duration
This commit is contained in:
@@ -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()}`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user