diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index bc2354f110..ee917c7500 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -502,6 +502,11 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi } function parseDate(viewValue) { + if (angular.isNumber(viewValue)) { + // presumably timestamp to date object + viewValue = new Date(viewValue); + } + if (!viewValue) { ngModel.$setValidity('date', true); return null; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index b673d162da..2b3517fb93 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1506,11 +1506,18 @@ describe('datepicker directive', function () { it('should be invalid initially', function() { expect(inputEl.hasClass('ng-invalid')).toBeTruthy(); }); + it('should be valid if model has been specified', function() { $rootScope.date = new Date(); $rootScope.$digest(); expect(inputEl.hasClass('ng-valid')).toBeTruthy(); }); + + it('should be valid if model value is a valid timestamp', function() { + $rootScope.date = Date.now(); + $rootScope.$digest(); + expect(inputEl.hasClass('ng-valid')).toBeTruthy(); + }); }); describe('use with `ng-change` directive', function() {