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) { diff --git a/spec/js/TimepickerSpec.js b/spec/js/TimepickerSpec.js index d7a73d36..0a851f20 100644 --- a/spec/js/TimepickerSpec.js +++ b/spec/js/TimepickerSpec.js @@ -413,6 +413,36 @@ 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; @@ -429,6 +459,36 @@ describe('Timepicker feature', function() { 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();