diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 75a13218fa..021ce60ef0 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 e6caa8cc76..1a9f85d65c 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1547,11 +1547,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() {