Merged PR 895: #2254 UI Datepicker ausgewählter Tag

#2254 UI Datepicker ausgewählter Tag

Related work items: #2254
This commit is contained in:
Andreas Schickinger
2021-10-06 15:05:18 +00:00
committed by Lorenz Hilpert
parent 02f8f747e1
commit 7b49fbc85c
2 changed files with 15 additions and 7 deletions

View File

@@ -90,11 +90,15 @@ export class DateAdapter {
return result;
}
parseDate(date: string) {
return new Date(date);
}
today(): Date {
return new Date(new Date().toJSON().slice(0, 10).replace(/-/g, '/'));
}
isValid(date: Date): boolean {
isValid(date: any): date is Date {
return date instanceof Date && !isNaN(date.getDate());
}

View File

@@ -87,16 +87,20 @@ export abstract class Datepicker {
this.setDisplayed(this.dateAdapter.addCalendarMonths(this.displayed, -1));
}
setSelected(date: Date, { emit: emitChanged }: SetPropertyOptions = { emit: true }) {
if (!this.dateAdapter.isValid(date)) {
setSelected(date: Date | string, { emit: emitChanged }: SetPropertyOptions = { emit: true }) {
let _date: Date;
if (this.dateAdapter.isValid(date)) {
_date = date;
} else if (typeof date === 'string') {
_date = this.dateAdapter.parseDate(date);
} else {
this.selectedSubject.next(undefined);
return;
}
if (this.dateAdapter.compareDate(this.selected, date) !== 0) {
this.selectedSubject.next(date);
if (this.dateAdapter.compareDate(this.selected, _date) !== 0) {
this.selectedSubject.next(_date);
if (emitChanged) {
this.selectedChange.emit(date);
this.selectedChange.emit(_date);
}
}
}