From ee7417071d1dd183768cef5596e2378ccd4ae0f7 Mon Sep 17 00:00:00 2001 From: Tasos Bekos Date: Tue, 25 Jun 2013 20:59:06 +0300 Subject: [PATCH] fix(timepicker): prevent date change --- src/timepicker/test/timepicker.spec.js | 26 +++++++++++++++++++++++++- src/timepicker/timepicker.js | 6 ++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/timepicker/test/timepicker.spec.js b/src/timepicker/test/timepicker.spec.js index bfa6114529..67adc49d7f 100644 --- a/src/timepicker/test/timepicker.spec.js +++ b/src/timepicker/test/timepicker.spec.js @@ -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(); @@ -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('')($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); diff --git a/src/timepicker/timepicker.js b/src/timepicker/timepicker.js index f9fac966d3..4646bf8205 100644 --- a/src/timepicker/timepicker.js +++ b/src/timepicker/timepicker.js @@ -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 ); }