This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
/**
* Test whether a Date instance is valid.
* A valid date returns a number for its timestamp, and NaN otherwise.
* NaN is never equal to itself.
* @returns {boolean}
*/
export function isValid() {
return this.getTime() === this.getTime();
}
/**
* Return a standard YYYY-MM-DD string for the Date instance.
* @returns {string} The date in YYYY-MM-DD format
*/
export function toDateInputString() {
const yyyy = this.getFullYear();
const mm = (this.getMonth() + 1).paddedString(2);
const dd = this.getDate().paddedString(2);
return `${yyyy}-${mm}-${dd}`;
}
/**
* Return a standard H:M:S.Z string for the Date instance.
* @returns {string} The time in H:M:S format
*/
export function toTimeInputString() {
return this.toTimeString().split(" ")[0];
}
// Define primitives on the Date prototype
Object.defineProperties(Date.prototype, {
isValid: {value: isValid},
toDateInputString: {value: toDateInputString},
toTimeInputString: {value: toTimeInputString}
});