export class DateWithParts implements HashidevDashboardCore.IDateWithParts { public month: string; public day: number; public year: number; public fullDate: Date; public setFullDate(date: Date) { this.fullDate = date; this.month = (date.getMonth() + 1).toString(); this.day = date.getDate(); this.year = date.getFullYear(); } public getDateAsString(): string { if (!this.fullDate || !this.year || !this.month || !this.day) { return ""; } return `${this.year}-${this.month}-${this.day}`; } public onChange() { // Validate if (!this.monthIsValid || !this.dayIsValid || !this.yearIsValid) { this.fullDate = null; return; } this.fullDate = new Date(this.year, Number(this.month)- 1, this.day); } public get dayIsValid(): boolean { return this.day && this.day > 0 && this.day < 32; } public get monthIsValid(): boolean { return this.month && Number(this.month) > 0 && Number(this.month) < 13; } public get yearIsValid(): boolean { return this.year && this.year > 0 && this.year < 2200; } public clear() { this.fullDate = null; this.day = null; this.year = null; this.month = "0"; } }