Skip to content

Commit 0e77c88

Browse files
vlio20Vlad Ioffe
andauthored
fixing isMonthDisabledCallback (#523)
* fixing isMonthDisabledCallback * reverting comment Co-authored-by: Vlad Ioffe <vioffe@outbrain.com>
1 parent 4bfb238 commit 0e77c88

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
]
9595
},
9696
"dependencies": {
97-
"moment": "^2.24.0",
98-
"tslib": "^2.0.0"
97+
"moment": "^2.24.0"
9998
}
10099
}

src/lib/date-picker/date-picker.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class DatePickerService {
7878
monthBtnFormat: pickerConfig.monthBtnFormat,
7979
monthBtnFormatter: pickerConfig.monthBtnFormatter,
8080
monthBtnCssClassCallback: pickerConfig.monthBtnCssClassCallback,
81+
isMonthDisabledCallback: pickerConfig.isMonthDisabledCallback,
8182
multipleYearsNavigateBy: pickerConfig.multipleYearsNavigateBy,
8283
showMultipleYearsNavigation: pickerConfig.showMultipleYearsNavigation,
8384
locale: pickerConfig.locale,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export class DayCalendarService {
175175
monthBtnFormat: componentConfig.monthBtnFormat,
176176
monthBtnFormatter: componentConfig.monthBtnFormatter,
177177
monthBtnCssClassCallback: componentConfig.monthBtnCssClassCallback,
178+
isMonthDisabledCallback: componentConfig.isMonthDisabledCallback,
178179
multipleYearsNavigateBy: componentConfig.multipleYearsNavigateBy,
179180
showMultipleYearsNavigation: componentConfig.showMultipleYearsNavigation,
180181
showGoToCurrent: componentConfig.showGoToCurrent,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {inject, TestBed} from '@angular/core/testing';
22
import * as momentNs from 'moment';
3+
import {Moment} from 'moment';
34
import {UtilsService} from '../common/services/utils/utils.service';
45
import {MonthCalendarService} from './month-calendar.service';
56
import {IMonth} from './month.model';
@@ -71,6 +72,34 @@ describe('Service: MonthCalendarService', () => {
7172
expect(service.isMonthDisabled(month.date, config1)).toBe(true);
7273
}));
7374

75+
it('should check the isDateDisabled when isMonthDisabledCallback provided',
76+
inject([MonthCalendarService], (service: MonthCalendarService) => {
77+
const month: IMonth = {
78+
date: moment('01`-01-2017', 'DD-MM-YYYY'),
79+
selected: false,
80+
currentMonth: false,
81+
disabled: false,
82+
text: moment('01-01-2017', 'DD-MM-YYYY').format('MMM')
83+
};
84+
const config1: any = {
85+
isMonthDisabledCallback: (m: Moment) => {
86+
return m.get('M') % 2 === 0;
87+
}
88+
};
89+
90+
for (let i = 0; i < 12; i++) {
91+
console.log(month.date.get('M'), i % 2, service.isMonthDisabled(month.date, config1));
92+
93+
if (i % 2 === 0) {
94+
expect(service.isMonthDisabled(month.date, config1)).toBe(true);
95+
} else {
96+
expect(service.isMonthDisabled(month.date, config1)).toBe(false);
97+
}
98+
99+
month.date.add(1, 'month');
100+
}
101+
}));
102+
74103
it('should check getDayBtnText method',
75104
inject([MonthCalendarService], (service: MonthCalendarService) => {
76105
const date = moment('05-04-2017', 'DD-MM-YYYY');

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export class MonthCalendarService {
6161
}
6262

6363
isMonthDisabled(date: Moment, config: IMonthCalendarConfig) {
64+
if (config.isMonthDisabledCallback) {
65+
return config.isMonthDisabledCallback(date);
66+
}
67+
6468
if (config.min && date.isBefore(config.min, 'month')) {
6569
return true;
6670
}

0 commit comments

Comments
 (0)