Skip to content

Commit

Permalink
fixing isMonthDisabledCallback (#523)
Browse files Browse the repository at this point in the history
* fixing isMonthDisabledCallback

* reverting comment

Co-authored-by: Vlad Ioffe <vioffe@outbrain.com>
  • Loading branch information
vlio20 and Vlad Ioffe committed Nov 10, 2020
1 parent 4bfb238 commit 0e77c88
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
]
},
"dependencies": {
"moment": "^2.24.0",
"tslib": "^2.0.0"
"moment": "^2.24.0"
}
}
1 change: 1 addition & 0 deletions src/lib/date-picker/date-picker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class DatePickerService {
monthBtnFormat: pickerConfig.monthBtnFormat,
monthBtnFormatter: pickerConfig.monthBtnFormatter,
monthBtnCssClassCallback: pickerConfig.monthBtnCssClassCallback,
isMonthDisabledCallback: pickerConfig.isMonthDisabledCallback,
multipleYearsNavigateBy: pickerConfig.multipleYearsNavigateBy,
showMultipleYearsNavigation: pickerConfig.showMultipleYearsNavigation,
locale: pickerConfig.locale,
Expand Down
1 change: 1 addition & 0 deletions src/lib/day-calendar/day-calendar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class DayCalendarService {
monthBtnFormat: componentConfig.monthBtnFormat,
monthBtnFormatter: componentConfig.monthBtnFormatter,
monthBtnCssClassCallback: componentConfig.monthBtnCssClassCallback,
isMonthDisabledCallback: componentConfig.isMonthDisabledCallback,
multipleYearsNavigateBy: componentConfig.multipleYearsNavigateBy,
showMultipleYearsNavigation: componentConfig.showMultipleYearsNavigation,
showGoToCurrent: componentConfig.showGoToCurrent,
Expand Down
29 changes: 29 additions & 0 deletions src/lib/month-calendar/month-calendar.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {inject, TestBed} from '@angular/core/testing';
import * as momentNs from 'moment';
import {Moment} from 'moment';
import {UtilsService} from '../common/services/utils/utils.service';
import {MonthCalendarService} from './month-calendar.service';
import {IMonth} from './month.model';
Expand Down Expand Up @@ -71,6 +72,34 @@ describe('Service: MonthCalendarService', () => {
expect(service.isMonthDisabled(month.date, config1)).toBe(true);
}));

it('should check the isDateDisabled when isMonthDisabledCallback provided',
inject([MonthCalendarService], (service: MonthCalendarService) => {
const month: IMonth = {
date: moment('01`-01-2017', 'DD-MM-YYYY'),
selected: false,
currentMonth: false,
disabled: false,
text: moment('01-01-2017', 'DD-MM-YYYY').format('MMM')
};
const config1: any = {
isMonthDisabledCallback: (m: Moment) => {
return m.get('M') % 2 === 0;
}
};

for (let i = 0; i < 12; i++) {
console.log(month.date.get('M'), i % 2, service.isMonthDisabled(month.date, config1));

if (i % 2 === 0) {
expect(service.isMonthDisabled(month.date, config1)).toBe(true);
} else {
expect(service.isMonthDisabled(month.date, config1)).toBe(false);
}

month.date.add(1, 'month');
}
}));

it('should check getDayBtnText method',
inject([MonthCalendarService], (service: MonthCalendarService) => {
const date = moment('05-04-2017', 'DD-MM-YYYY');
Expand Down
4 changes: 4 additions & 0 deletions src/lib/month-calendar/month-calendar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class MonthCalendarService {
}

isMonthDisabled(date: Moment, config: IMonthCalendarConfig) {
if (config.isMonthDisabledCallback) {
return config.isMonthDisabledCallback(date);
}

if (config.min && date.isBefore(config.min, 'month')) {
return true;
}
Expand Down

0 comments on commit 0e77c88

Please sign in to comment.