Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/scripts/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Module.constant('datePickerConfig', {
Module.filter('mFormat', function () {
return function (m, format, tz) {
if (!(moment.isMoment(m))) {
return moment(m).format(format);
var value = moment(m);
return value.isValid() ? value.format(format) : null;
}
return tz ? moment.tz(m, tz).format(format) : m.format(format);
};
Expand Down
3 changes: 2 additions & 1 deletion dist/angular-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var Module = angular.module('datePicker', []);
Module.filter('mFormat', function () {
return function (m, format, tz) {
if (!(moment.isMoment(m))) {
return (m) ? moment(m).format(format) : '';
var value = moment(m);
return value.isValid() ? value.format(format) : null;
}
return tz ? moment.tz(m, tz).format(format) : m.format(format);
};
Expand Down
14 changes: 14 additions & 0 deletions test/spec/datePickerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ describe('Test date Picker Filter', function(){

expect(formattedDate).toBe('2015_01_02');
});

it('returns null when receiving an invalid date', function() {
var date = 'an invalid date';
var formattedDate = mFormatFilter(date, 'YYYY_MM_DD');

expect(formattedDate).toBe(null);
});

it('returns null when receiving null', function() {
var date = null;
var formattedDate = mFormatFilter(date, 'YYYY_MM_DD');

expect(formattedDate).toBe(null);
});
});

describe('Test date Picker Directive', function(){
Expand Down