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

Commit

Permalink
fix(datepicker): set default zero time after no date selected
Browse files Browse the repository at this point in the history
Closes #1065
  • Loading branch information
bekos committed Dec 9, 2013
1 parent 60515ae commit 93cd0df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])

scope.select = function( date ) {
if ( mode === 0 ) {
var dt = new Date( ngModel.$modelValue );
var dt = ngModel.$modelValue ? new Date( ngModel.$modelValue ) : new Date(0, 0, 0, 0, 0, 0, 0);
dt.setFullYear( date.getFullYear(), date.getMonth(), date.getDate() );
ngModel.$setViewValue( dt );
refill( true );
Expand Down
41 changes: 23 additions & 18 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1294,26 +1294,31 @@ describe('datepicker directive', function () {
});
});
});
});

describe('datepicker directive with empty initial state', function () {
var $rootScope, element;
beforeEach(module('ui.bootstrap.datepicker'));
beforeEach(module('template/datepicker/datepicker.html'));
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$rootScope.date = null;
element = $compile('<datepicker ng-model="$parent.date"></datepicker>')($rootScope);
$rootScope.$digest();
}));
describe('datepicker directive with empty initial state', function () {
beforeEach(inject(function() {
$rootScope.date = null;
element = $compile('<datepicker ng-model="$parent.date"></datepicker>')($rootScope);
$rootScope.$digest();
}));

it('is a `<table>` element', function() {
expect(element.prop('tagName')).toBe('TABLE');
expect(element.find('thead').find('tr').length).toBe(2);
});
it('is a `<table>` element', function() {
expect(element.prop('tagName')).toBe('TABLE');
expect(element.find('thead').find('tr').length).toBe(2);
});

it('is shows rows with days', function() {
expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
it('is shows rows with days', function() {
expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
});

it('sets default 00:00:00 time for selected date', function() {
$rootScope.date = new Date('August 1, 2013');
$rootScope.$digest();
$rootScope.date = null;
$rootScope.$digest();

clickOption(2, 0);
expect($rootScope.date).toEqual(new Date('August 11, 2013 00:00:00'));
});
});
});

0 comments on commit 93cd0df

Please sign in to comment.