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(ui5-duration-picker): maxValue can be greater than 23:59:59 #1666

Merged
merged 1 commit into from
May 21, 2020
Merged
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
24 changes: 17 additions & 7 deletions packages/main/src/DurationPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ class DurationPicker extends UI5Element {
currentSeconds = this.getSecondsFromFormattedValue(destructuredValues); // this.hideHours && this.hideHours ? destructuredValues[0] : {};

if (currentHours > -1) {
if (currentHours > this._maxValue[0]) {
if (parseInt(currentHours) > parseInt(this._maxValue[0])) {
currentHours = this._maxValue[0];
}

this.selectedHours = this._formatSelectedValue(currentHours, 23);
this.selectedHours = this._formatSelectedValue(currentHours, parseInt(this.readFormattedValue(this.maxValue)));
}

if (currentMinutes > -1) {
Expand All @@ -331,7 +331,7 @@ class DurationPicker extends UI5Element {
}
if (this._maxValue[0] && this.selectedHours === this._maxValue[0]) {
currentMinutes = currentMinutes > this._maxValue[1] ? this._maxValue[1] : currentMinutes;
} else if (currentMinutes > this._maxValue[1]) {
} else if (parseInt(currentMinutes) > parseInt(this._maxValue[1])) {
currentMinutes = this._maxValue[1];
}

Expand All @@ -344,15 +344,15 @@ class DurationPicker extends UI5Element {
}
if (this._maxValue[0] && this._maxValue[1] && this.selectedHours >= this._maxValue[0] && this.selectedSeconds >= this._maxValue[1]) {
currentSeconds = currentSeconds > this._maxValue[2] ? this._maxValue[2] : currentSeconds;
} else if (currentSeconds > this._maxValue[2]) {
} else if (parseInt(currentSeconds) > parseInt(this._maxValue[2])) {
currentSeconds = this._maxValue[2];
}

this.selectedSeconds = this._formatSelectedValue(currentSeconds, 59);
}
}

_formatSelectedValue(currentValue, maximum) {
_formatSelectedValue(currentValue, maximum = Infinity) {
if (currentValue.length === 1) {
return `0${currentValue}`;
}
Expand Down Expand Up @@ -494,8 +494,18 @@ class DurationPicker extends UI5Element {
}

get hoursArray() {
const currentHours = parseInt(this.readFormattedValue(this.maxValue)[0]);
const hours = currentHours && currentHours > 0 && currentHours < 23 ? currentHours + 1 : 24;
const _maxHours = parseInt(this.readFormattedValue(this.maxValue)[0]);
const _currHours = parseInt(this.selectedHours) + 1;
let hours;

if (_maxHours) {
hours = _maxHours + 1;
} else if (_currHours < 24) {
hours = 24;
} else {
hours = _currHours;
}

return this.generateTimeItemsArray(hours);
}

Expand Down