Skip to content

Commit

Permalink
fix: always reset time when setting range (#66)
Browse files Browse the repository at this point in the history
* fix: always reset time to begin of range when setting range

* chore: add test for reset time when setting range

* chore: correct to correct word
  • Loading branch information
jajugoguma authored Aug 12, 2021
1 parent 74b375e commit 903b924
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/js/timepicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,9 @@ var TimePicker = defineClass(
* @private
*/
applyRange: function(beginHour, beginMin, endHour) {
this.setTime(beginHour, beginMin);
if (this.isLaterThanSetTime(beginHour, beginMin)) {
this.setTime(beginHour, beginMin);
}
this.setDisabledHours();

if (this.showMeridiem) {
Expand Down Expand Up @@ -836,6 +838,17 @@ var TimePicker = defineClass(
minute <= END_NUMBER_OF_MINUTE;
},

/**
* Compare given time with set time
* @param {number} hour - given hour
* @param {number} minute - given minute
* @returns {boolean} result of compare
* @private
*/
isLaterThanSetTime: function(hour, minute) {
return hour > this.hour || (hour === this.hour && minute > this.minute);
},

/**
* Compare two times
* it returns
Expand Down
20 changes: 20 additions & 0 deletions test/timepicker/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,26 @@ describe('Set selectable range', function() {
expect(selectOptions).toMatchObject(unrangedMins);
});

it('should set time to range begin if it is later than set time', function() {
var start = makeRangeObj(10, 35);

timepickerNoMeridiem.setTime(9, 30);
timepickerNoMeridiem.setRange(start);

expect(timepickerNoMeridiem.getHour()).toBe(10);
expect(timepickerNoMeridiem.getMinute()).toBe(35);
});

it('should not reset time if the time which is begin of range is earlier than set time', function() {
var start = makeRangeObj(8, 35);

timepickerNoMeridiem.setTime(9, 30);
timepickerNoMeridiem.setRange(start);

expect(timepickerNoMeridiem.getHour()).toBe(9);
expect(timepickerNoMeridiem.getMinute()).toBe(30);
});

it('should disable a meridiem selector when range included in the other', function() {
var start = makeRangeObj(6, 30);
var end = makeRangeObj(11, 30);
Expand Down

0 comments on commit 903b924

Please sign in to comment.