Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
fix: onDateRangeSelect callback dates should be dates and not moment …
Browse files Browse the repository at this point in the history
…objects

Closes #518
  • Loading branch information
Matt Lewis committed Jan 9, 2017
1 parent d4a4d1f commit 65710b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/directives/mwlCalendarHourList.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ angular
if (vm.dateRangeSelect) {
vm.dateRangeSelect.endDate = date;
if (vm.dateRangeSelect.endDate > vm.dateRangeSelect.startDate) {
vm.onDateRangeSelect({calendarRangeStartDate: vm.dateRangeSelect.startDate, calendarRangeEndDate: vm.dateRangeSelect.endDate});
vm.onDateRangeSelect({
calendarRangeStartDate: vm.dateRangeSelect.startDate.toDate(),
calendarRangeEndDate: vm.dateRangeSelect.endDate.toDate()
});
}
delete vm.dateRangeSelect;
}
Expand Down
16 changes: 8 additions & 8 deletions test/unit/directives/mwlCalendarHourList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,27 @@ describe('mwlCalendarHourList directive', function() {

it('should call the onDateRangeSelect callback if there is a valid date range', function() {
MwlCalendarCtrl.onDateRangeSelect = sinon.spy();
var date1 = new Date();
var date2 = new Date(Date.now() + 100000);
var date1 = moment();
var date2 = moment(Date.now() + 100000);
MwlCalendarCtrl.dateRangeSelect = {
startDate: date1,
endDate: new Date(Date.now() + 10)
endDate: moment(Date.now() + 10)
};
MwlCalendarCtrl.onDragSelectEnd(date2);
expect(MwlCalendarCtrl.onDateRangeSelect).to.have.been.calledWith({
calendarRangeStartDate: date1,
calendarRangeEndDate: date2
calendarRangeStartDate: date1.toDate(),
calendarRangeEndDate: date2.toDate()
});
expect(MwlCalendarCtrl.dateRangeSelect).to.be.undefined;
});

it('should not call the onDateRangeSelect callback if there is an invalid date range', function() {
MwlCalendarCtrl.onDateRangeSelect = sinon.spy();
var date1 = new Date();
var date2 = new Date(Date.now() - 100000);
var date1 = moment();
var date2 = moment(Date.now() - 100000);
MwlCalendarCtrl.dateRangeSelect = {
startDate: date1,
endDate: new Date(Date.now() - 10)
endDate: moment(Date.now() - 10)
};
MwlCalendarCtrl.onDragSelectEnd(date2);
expect(MwlCalendarCtrl.onDateRangeSelect).not.to.have.been.called;
Expand Down

0 comments on commit 65710b4

Please sign in to comment.