Skip to content

Commit b9747ef

Browse files
committed
fix(calendar): render the calendar when min and max date are same date
1 parent 5ad88b5 commit b9747ef

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/calendar/src/LionCalendar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,13 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
430430
this.minDate && this.minDate > date ? new Date(this.minDate) : new Date(date);
431431
const pastDate = this.maxDate && this.maxDate < date ? new Date(this.maxDate) : new Date(date);
432432

433+
if (this.minDate && this.minDate > date) {
434+
futureDate.setDate(futureDate.getDate() - 1);
435+
}
436+
if (this.maxDate && this.maxDate < date) {
437+
pastDate.setDate(pastDate.getDate() + 1);
438+
}
439+
433440
let i = 0;
434441
do {
435442
i += 1;

packages/calendar/test/lion-calendar.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,20 @@ describe('<lion-calendar>', () => {
339339
clock.restore();
340340
});
341341

342+
it('should set centralDate to the unique valid value when minDate and maxDate are equal', async () => {
343+
const clock = sinon.useFakeTimers({ now: new Date('2019/06/03').getTime() });
344+
345+
const el = await fixture(html`
346+
<lion-calendar
347+
.minDate="${new Date('2019/07/03')}"
348+
.maxDate="${new Date('2019/07/03')}"
349+
></lion-calendar>
350+
`);
351+
expect(isSameDate(el.centralDate, new Date('2019/07/03')), 'central date').to.be.true;
352+
353+
clock.restore();
354+
});
355+
342356
describe('Normalization', () => {
343357
it('normalizes all generated dates', async () => {
344358
function isNormalizedDate(d) {
@@ -504,7 +518,7 @@ describe('<lion-calendar>', () => {
504518
elObj.previousMonthButtonEl.click();
505519
await el.updateComplete;
506520
expect(elObj.activeMonthAndYear).to.equal('November 2000');
507-
expect(isSameDate(el.centralDate, new Date('2000/11/21'))).to.be.true;
521+
expect(isSameDate(el.centralDate, new Date('2000/11/20'))).to.be.true;
508522

509523
clock.restore();
510524
});
@@ -527,7 +541,7 @@ describe('<lion-calendar>', () => {
527541
elObj.nextMonthButtonEl.click();
528542
await el.updateComplete;
529543
expect(elObj.activeMonthAndYear).to.equal('January 2001');
530-
expect(isSameDate(el.centralDate, new Date('2001/01/09'))).to.be.true;
544+
expect(isSameDate(el.centralDate, new Date('2001/01/10'))).to.be.true;
531545

532546
clock.restore();
533547
});

0 commit comments

Comments
 (0)