@nodescript/stdlib
Version:
Standard Node Definitions
17 lines (16 loc) • 436 B
JavaScript
export class InvalidDateError extends Error {
constructor() {
super(...arguments);
this.name = this.constructor.name;
this.message = 'Invalid date';
}
}
export function parseDate(value) {
if (!value) {
return new Date();
}
if (value instanceof Date || typeof value === 'string' || typeof value === 'number') {
return new Date(value);
}
throw new InvalidDateError();
}