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

Commit

Permalink
fix(timepicker): prevent date change
Browse files Browse the repository at this point in the history
  • Loading branch information
bekos committed Jun 25, 2013
1 parent 1fb30d1 commit ee74170
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/timepicker/test/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('timepicker directive', function () {
expect(getModelState()).toEqual([23, 0]);
});

it('changes only the time part', function() {
it('changes only the time part when hours change', function() {
$rootScope.time = newTime(23, 50);
$rootScope.$digest();

Expand All @@ -228,6 +228,30 @@ describe('timepicker directive', function () {
expect(date).toEqual($rootScope.time.getDate());
});

it('changes only the time part when minutes change', function() {
element = $compile('<timepicker ng-model="time" minute-step="15"></timepicker>')($rootScope);
$rootScope.time = newTime(0, 0);
$rootScope.$digest();

var date = $rootScope.time.getDate();
var up = getMinutesButton(true);
doClick(up, 2);
expect(getTimeState()).toEqual(['12', '30', 'AM']);
expect(getModelState()).toEqual([0, 30]);
expect(date).toEqual($rootScope.time.getDate());

var down = getMinutesButton(false);
doClick(down, 2);
expect(getTimeState()).toEqual(['12', '00', 'AM']);
expect(getModelState()).toEqual([0, 0]);
expect(date).toEqual($rootScope.time.getDate());

doClick(down, 2);
expect(getTimeState()).toEqual(['11', '30', 'PM']);
expect(getModelState()).toEqual([23, 30]);
expect(date).toEqual($rootScope.time.getDate());
});

it('responds properly on "mousewheel" events', function() {
var inputs = element.find('input');
var hoursEl = inputs.eq(0), minutesEl = inputs.eq(1);
Expand Down
6 changes: 2 additions & 4 deletions src/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ angular.module('ui.bootstrap.timepicker', [])

function addMinutes( minutes ) {
var dt = new Date( selected.getTime() + minutes * 60000 );
if ( dt.getDate() !== selected.getDate()) {
dt.setDate( dt.getDate() - 1 );
}
selected.setTime( dt.getTime() );
selected.setHours( dt.getHours() );
selected.setMinutes( dt.getMinutes() );
scope.model = new Date( selected );
}

Expand Down

0 comments on commit ee74170

Please sign in to comment.