Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ngOnInit(): void {
if (!this.value) {
this.value = new CandyDate(); // Show today by default
}
this.render();
}
it('should support two-way binding without model', () => {
fixture.detectChanges();
const now = new Date();
const calendar = fixture.debugElement.queryAll(By.directive(Calendar))[1].injector.get(Calendar);
expect(calendar.activeDate.nativeDate).toBe(component.date0);
calendar.onDateSelect(new CandyDate(now));
fixture.detectChanges();
expect(component.date0).toBe(now);
});
onClickPresetRange(val: PresetRanges[keyof PresetRanges]): void {
const value = typeof val === 'function' ? val() : val;
if (value) {
this.setValue([new CandyDate(value[0]), new CandyDate(value[1])]);
this.resultOk.emit();
}
}
onSelectTime(date: Date): void {
this.selectTime.emit(new CandyDate(date));
}
this.nzValue = value ? (value as Date[]).map(val => new CandyDate(val)) : [];
} else {
@Input() set nzValue(value: Date) {
this.updateDate(new CandyDate(value), false);
}
@Output() readonly nzValueChange: EventEmitter = new EventEmitter();
private makePanelMonths(): PanelMonthData[][] {
const months: PanelMonthData[][] = [];
const currentMonth = this.value.getMonth();
const today = new CandyDate();
let monthValue = 0;
for (let rowIndex = 0; rowIndex < MAX_ROW; rowIndex++) {
months[rowIndex] = [];
for (let colIndex = 0; colIndex < MAX_COL; colIndex++) {
const month = this.value.setMonth(monthValue);
const disabled = this.disabledDate ? this.disabledDate(this.value.setMonth(monthValue).nativeDate) : false;
const content = this.dateHelper.format(month.nativeDate, 'MMM');
const cell: PanelMonthData = (months[rowIndex][colIndex] = {
value: month.nativeDate,
disabled,
content,
month: monthValue,
title: content,
classMap: null,
writeValue(value: Date | null): void {
this.updateDate(new CandyDate(value as Date), false);
this.cdr.markForCheck();
}
private normalizeRangeValue(value: CandyDate[]): CandyDate[] {
const [start, end] = value;
const newStart = start || new CandyDate();
const newEnd = end && end.isSameMonth(newStart) ? end.addMonths(1) : end || newStart.addMonths(1);
return [newStart, newEnd];
}