diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index e04543aa19..599f3c3562 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -442,7 +442,16 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon }); scope.select = function( date ) { - scope.dateSelection( date === 'today' ? new Date() : date); + if (date === 'today') { + var today = new Date(); + if (angular.isDate(ngModel.$modelValue)) { + date = new Date(ngModel.$modelValue); + date.setFullYear(today.getFullYear(), today.getMonth(), today.getDate()); + } else { + date = new Date(today.setHours(0, 0, 0, 0)); + } + } + scope.dateSelection( date ); }; var $popup = $compile(popupEl)(scope); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 1bafc4d336..9ecec1c69c 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1042,7 +1042,7 @@ describe('datepicker directive', function () { expect(dropdownEl.find('li').length).toBe(2); }); - it('should have four buttons', function() { + it('should have three buttons', function() { expect(buttons.length).toBe(3); expect(buttons.eq(0).text()).toBe('Today'); @@ -1050,6 +1050,33 @@ describe('datepicker directive', function () { expect(buttons.eq(2).text()).toBe('Done'); }); + it('should have a button to set today date without altering time part', function() { + var today = new Date(); + buttons.eq(0).click(); + expect($rootScope.date.getFullYear()).toBe(today.getFullYear()); + expect($rootScope.date.getMonth()).toBe(today.getMonth()); + expect($rootScope.date.getDate()).toBe(today.getDate()); + + expect($rootScope.date.getHours()).toBe(15); + expect($rootScope.date.getMinutes()).toBe(30); + expect($rootScope.date.getSeconds()).toBe(0); + }); + + it('should have a button to set today date if blank', function() { + $rootScope.date = null; + $rootScope.$digest(); + + var today = new Date(); + buttons.eq(0).click(); + expect($rootScope.date.getFullYear()).toBe(today.getFullYear()); + expect($rootScope.date.getMonth()).toBe(today.getMonth()); + expect($rootScope.date.getDate()).toBe(today.getDate()); + + expect($rootScope.date.getHours()).toBe(0); + expect($rootScope.date.getMinutes()).toBe(0); + expect($rootScope.date.getSeconds()).toBe(0); + }); + it('should have a button to clear value', function() { buttons.eq(1).click(); expect($rootScope.date).toBe(null);