Skip to content

Commit db5e455

Browse files
author
Vlad Ioffe
committed
Merge branch '12.0.4' of github.com:vlio20/angular-datepicker into 12.0.4
2 parents aee8c45 + c01f209 commit db5e455

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/lib/day-calendar/day-calendar.service.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ describe('Service: Calendar', () => {
9797
expect(monthWeeks[5][6].date.format('DD-MM-YYYY')).toBe('06-11-2016');
9898
expect(monthWeeks[2][1].selected).toBe(false);
9999
expect(monthWeeks[2][3].selected).toBe(false);
100+
101+
102+
const today = moment('11-10-2016', 'DD-MM-YYYY').toDate();
103+
jasmine.clock().mockDate(today);
104+
monthWeeks = service.generateMonthArray(
105+
{
106+
firstDayOfWeek: 'mo'
107+
},
108+
moment('test', 'DD-MM-YYYY'),
109+
[]
110+
);
111+
expect(monthWeeks[0][0].date.format('DD-MM-YYYY')).toBe('26-09-2016');
112+
expect(monthWeeks[5][6].date.format('DD-MM-YYYY')).toBe('06-11-2016');
113+
expect(monthWeeks[2][1].selected).toBe(false);
114+
expect(monthWeeks[2][3].selected).toBe(false);
100115
}));
101116

102117
it('should check the generateWeekdays method', inject([DayCalendarService],

src/lib/day-calendar/day-calendar.service.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,26 @@ export class DayCalendarService {
5151
}
5252

5353
generateMonthArray(config: IDayCalendarConfigInternal, month: Moment, selected: Moment[]): IDay[][] {
54+
const parsedMonth = month.isValid() ? month.clone() : moment();
5455
let monthArray: IDay[][] = [];
5556
const firstDayOfWeekIndex = this.DAYS.indexOf(config.firstDayOfWeek);
56-
const firstDayOfBoard = month.clone().startOf('month');
57+
const firstDayOfBoard = parsedMonth.clone().startOf('month');
5758

5859
while (firstDayOfBoard.day() !== firstDayOfWeekIndex) {
5960
firstDayOfBoard.subtract(1, 'day');
6061
}
6162

6263
const current = firstDayOfBoard.clone();
63-
const prevMonth = month.clone().subtract(1, 'month');
64-
const nextMonth = month.clone().add(1, 'month');
64+
const prevMonth = parsedMonth.clone().subtract(1, 'month');
65+
const nextMonth = parsedMonth.clone().add(1, 'month');
6566
const today = moment();
6667

6768
const daysOfCalendar: IDay[] = this.utilsService.createArray(42)
6869
.reduce((array: IDay[]) => {
6970
array.push({
7071
date: current.clone(),
7172
selected: !!selected.find(selectedDay => current.isSame(selectedDay, 'day')),
72-
currentMonth: current.isSame(month, 'month'),
73+
currentMonth: current.isSame(parsedMonth, 'month'),
7374
prevMonth: current.isSame(prevMonth, 'month'),
7475
nextMonth: current.isSame(nextMonth, 'month'),
7576
currentDay: current.isSame(today, 'day'),
@@ -91,7 +92,7 @@ export class DayCalendarService {
9192
});
9293

9394
if (!config.showNearMonthDays) {
94-
monthArray = this.removeNearMonthWeeks(month, monthArray);
95+
monthArray = this.removeNearMonthWeeks(parsedMonth, monthArray);
9596
}
9697

9798
return monthArray;

0 commit comments

Comments
 (0)