Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(datepicker): Today button should not set time
Browse files Browse the repository at this point in the history
Fixes #1726
Closes #1808
  • Loading branch information
bekos authored and pkozlowski-opensource committed Feb 15, 2014
1 parent dea67b0 commit e199349
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 28 additions & 1 deletion src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,41 @@ 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');
expect(buttons.eq(1).text()).toBe('Clear');
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);
Expand Down

0 comments on commit e199349

Please sign in to comment.