Skip to content

Commit

Permalink
Fixed #15818 - Fix calendar range selection shown date
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermeb committed Jun 11, 2024
1 parent e5f593e commit 71dea69
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/app/components/calendar/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2018,4 +2018,43 @@ describe('Calendar', () => {
expect(selectdateSpy).toHaveBeenCalled();
expect(calendar.value).toEqual(minDate);
});

it('should display end date instead of start date in range selection', () => {
calendar.selectionMode = 'range';
calendar.value = [new Date('2024-03-01'), new Date('2024-04-01')];

calendar.updateUI();
expect(calendar.currentMonth).toBe(3);
expect(calendar.currentYear).toBe(2024);
});

it('should display start date instead of default date in range selection', () => {
calendar.selectionMode = 'range';
calendar.value = [new Date('2024-03-01'), null];

calendar.updateUI();
expect(calendar.currentMonth).toBe(2);
expect(calendar.currentYear).toBe(2024);
});

it('should use default date when no range is selected in range selection', () => {
calendar.selectionMode = 'range';
calendar.defaultDate = new Date('2024-01-01');

calendar.updateUI();
expect(calendar.currentMonth).toBe(0);
expect(calendar.currentYear).toBe(2024);
});

it('should use current date when no default date and no range is selected in range selection', () => {
jasmine.clock().install();
jasmine.clock().mockDate(new Date('2024-06-11'));
calendar.selectionMode = 'range';

calendar.updateUI();
expect(calendar.currentMonth).toBe(5);
expect(calendar.currentYear).toBe(2024);

jasmine.clock().uninstall();
});
});
2 changes: 1 addition & 1 deletion src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
updateUI() {
let propValue = this.value;
if (Array.isArray(propValue)) {
propValue = propValue.length === 2 ? propValue[1] : propValue[0];
propValue = propValue[1] || propValue[0];
}

let val = this.defaultDate && this.isValidDate(this.defaultDate) && !this.value ? this.defaultDate : propValue && this.isValidDate(propValue) ? propValue : new Date();
Expand Down

0 comments on commit 71dea69

Please sign in to comment.