Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always reset time when setting range #66

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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