From f814af62eb845fd36ff6114b67858ae45f538250 Mon Sep 17 00:00:00 2001 From: smistir Date: Fri, 8 Jan 2016 13:03:17 -0600 Subject: [PATCH 1/3] Update bootstrap-timepicker.js Updated decrementMinute to behave similar to incrementMinute such that decrement will first round down if current value is not a multiple of this.minuteStep. **incrementMinute will apply the increment and then remove the remaining so that the new value is the next-step up (this.minute==2 with increment applied will result in "15" with a this.minuteStep==15). Previous implementation would not round decrement (this.minute==2 and this.minuteStep==15 will result in the minute becoming "47" instead of "0". --- js/bootstrap-timepicker.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-timepicker.js b/js/bootstrap-timepicker.js index bbb923c5..803efdb6 100644 --- a/js/bootstrap-timepicker.js +++ b/js/bootstrap-timepicker.js @@ -147,7 +147,12 @@ if (step) { newVal = this.minute - step; } else { - newVal = this.minute - this.minuteStep; + if(this.minuteStep > 0 && (this.minute % this.minuteStep) > 0) { + newVal = this.minute - (this.minute % this.minuteStep); + } + else { + newVal = this.minute - this.minuteStep; + } } if (newVal < 0) { From 8aa2729780ea65e49315457003db7f77b3fda7f1 Mon Sep 17 00:00:00 2001 From: smistir Date: Wed, 13 Jan 2016 08:33:49 -0600 Subject: [PATCH 2/3] Update TimepickerSpec.js Added UnitTest test-cases to test when the initial value is not a Multiple of the step for incrementMinute and decrementMinute --- spec/js/TimepickerSpec.js | 64 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/spec/js/TimepickerSpec.js b/spec/js/TimepickerSpec.js index d7a73d36..3523c9c2 100644 --- a/spec/js/TimepickerSpec.js +++ b/spec/js/TimepickerSpec.js @@ -412,7 +412,37 @@ describe('Timepicker feature', function() { expect(tp2.minute).toBe(30); }); - + + it('should increment minutes with incrementMinute method using Step and Rounding when initial value is not a Multiple of the Step', function () { + expect(tp1).toBeDefined(); + expect(tp1.minuteStep).toBe(15); + + tp1.setTime('11:00'); //Quick test to verify expected results + var currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.incrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:15 AM'); + + tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:02 AM'); + + tp1.incrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:15 AM'); + + tp1.incrementMinute(); //After the first rounded-increment, make sure further increments follow step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:30 AM'); + }); + it('should decrement minutes with decrementMinute method', function() { tp1.hour = 11; tp1.minute = 0; @@ -428,7 +458,37 @@ describe('Timepicker feature', function() { expect(tp2.hour).toBe(10); expect(tp2.minute).toBe(30); }); - + + it('should decrement minutes with decrementMinute method using Step and Rounding when initial value is not a Multiple of the Step', function () { + expect(tp1).toBeDefined(); + expect(tp1.minuteStep).toBe(15); + + tp1.setTime('11:00'); //Quick test to verify expected results + var currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.decrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('10:45 AM'); + + tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:02 AM'); + + tp1.decrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.decrementMinute(); //After the first rounded-decrement, make sure further decrements follow step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('10:45 AM'); + }); + it('should increment hour if minutes increment past 59', function() { $input1.val('11:55 AM'); tp1.updateFromElementVal(); From 111e1ee93d34037d99dd3c7c5fe838cf85ea6d96 Mon Sep 17 00:00:00 2001 From: smistir Date: Wed, 13 Jan 2016 09:02:32 -0600 Subject: [PATCH 3/3] Update TimepickerSpec.js fixed formatting issues within the file --- spec/js/TimepickerSpec.js | 120 +++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/spec/js/TimepickerSpec.js b/spec/js/TimepickerSpec.js index 3523c9c2..0a851f20 100644 --- a/spec/js/TimepickerSpec.js +++ b/spec/js/TimepickerSpec.js @@ -412,37 +412,37 @@ describe('Timepicker feature', function() { expect(tp2.minute).toBe(30); }); - + it('should increment minutes with incrementMinute method using Step and Rounding when initial value is not a Multiple of the Step', function () { - expect(tp1).toBeDefined(); - expect(tp1.minuteStep).toBe(15); - - tp1.setTime('11:00'); //Quick test to verify expected results - var currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:00 AM'); - - tp1.incrementMinute(); - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:15 AM'); - - tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:02 AM'); - - tp1.incrementMinute(); - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:15 AM'); - - tp1.incrementMinute(); //After the first rounded-increment, make sure further increments follow step - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:30 AM'); - }); - + expect(tp1).toBeDefined(); + expect(tp1.minuteStep).toBe(15); + + tp1.setTime('11:00'); //Quick test to verify expected results + var currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.incrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:15 AM'); + + tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:02 AM'); + + tp1.incrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:15 AM'); + + tp1.incrementMinute(); //After the first rounded-increment, make sure further increments follow step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:30 AM'); + }); + it('should decrement minutes with decrementMinute method', function() { tp1.hour = 11; tp1.minute = 0; @@ -458,37 +458,37 @@ describe('Timepicker feature', function() { expect(tp2.hour).toBe(10); expect(tp2.minute).toBe(30); }); - + it('should decrement minutes with decrementMinute method using Step and Rounding when initial value is not a Multiple of the Step', function () { - expect(tp1).toBeDefined(); - expect(tp1.minuteStep).toBe(15); - - tp1.setTime('11:00'); //Quick test to verify expected results - var currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:00 AM'); - - tp1.decrementMinute(); - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('10:45 AM'); - - tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:02 AM'); - - tp1.decrementMinute(); - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('11:00 AM'); - - tp1.decrementMinute(); //After the first rounded-decrement, make sure further decrements follow step - currentTime = tp1.getTime(); - expect(currentTime).toBeDefined(); - expect(currentTime).toBe('10:45 AM'); - }); - + expect(tp1).toBeDefined(); + expect(tp1.minuteStep).toBe(15); + + tp1.setTime('11:00'); //Quick test to verify expected results + var currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.decrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('10:45 AM'); + + tp1.setTime('11:02'); //Setup test with a time that is not a multiple of step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:02 AM'); + + tp1.decrementMinute(); + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('11:00 AM'); + + tp1.decrementMinute(); //After the first rounded-decrement, make sure further decrements follow step + currentTime = tp1.getTime(); + expect(currentTime).toBeDefined(); + expect(currentTime).toBe('10:45 AM'); + }); + it('should increment hour if minutes increment past 59', function() { $input1.val('11:55 AM'); tp1.updateFromElementVal();