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

Commit 93cd0df

Browse files
committedDec 9, 2013
fix(datepicker): set default zero time after no date selected
Closes #1065
1 parent 60515ae commit 93cd0df

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed
 

‎src/datepicker/datepicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
217217

218218
scope.select = function( date ) {
219219
if ( mode === 0 ) {
220-
var dt = new Date( ngModel.$modelValue );
220+
var dt = ngModel.$modelValue ? new Date( ngModel.$modelValue ) : new Date(0, 0, 0, 0, 0, 0, 0);
221221
dt.setFullYear( date.getFullYear(), date.getMonth(), date.getDate() );
222222
ngModel.$setViewValue( dt );
223223
refill( true );

‎src/datepicker/test/datepicker.spec.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -1294,26 +1294,31 @@ describe('datepicker directive', function () {
12941294
});
12951295
});
12961296
});
1297-
});
12981297

1299-
describe('datepicker directive with empty initial state', function () {
1300-
var $rootScope, element;
1301-
beforeEach(module('ui.bootstrap.datepicker'));
1302-
beforeEach(module('template/datepicker/datepicker.html'));
1303-
beforeEach(inject(function(_$compile_, _$rootScope_) {
1304-
$compile = _$compile_;
1305-
$rootScope = _$rootScope_;
1306-
$rootScope.date = null;
1307-
element = $compile('<datepicker ng-model="$parent.date"></datepicker>')($rootScope);
1308-
$rootScope.$digest();
1309-
}));
1298+
describe('datepicker directive with empty initial state', function () {
1299+
beforeEach(inject(function() {
1300+
$rootScope.date = null;
1301+
element = $compile('<datepicker ng-model="$parent.date"></datepicker>')($rootScope);
1302+
$rootScope.$digest();
1303+
}));
13101304

1311-
it('is a `<table>` element', function() {
1312-
expect(element.prop('tagName')).toBe('TABLE');
1313-
expect(element.find('thead').find('tr').length).toBe(2);
1314-
});
1305+
it('is a `<table>` element', function() {
1306+
expect(element.prop('tagName')).toBe('TABLE');
1307+
expect(element.find('thead').find('tr').length).toBe(2);
1308+
});
13151309

1316-
it('is shows rows with days', function() {
1317-
expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
1310+
it('is shows rows with days', function() {
1311+
expect(element.find('tbody').find('tr').length).toBeGreaterThan(3);
1312+
});
1313+
1314+
it('sets default 00:00:00 time for selected date', function() {
1315+
$rootScope.date = new Date('August 1, 2013');
1316+
$rootScope.$digest();
1317+
$rootScope.date = null;
1318+
$rootScope.$digest();
1319+
1320+
clickOption(2, 0);
1321+
expect($rootScope.date).toEqual(new Date('August 11, 2013 00:00:00'));
1322+
});
13181323
});
13191324
});

0 commit comments

Comments
 (0)