Skip to content

Commit

Permalink
fix(ui5-duration-picker): make maxValue work with values greater than…
Browse files Browse the repository at this point in the history
… 23:59:59 (#1666)
  • Loading branch information
fifoosid authored May 21, 2020
1 parent 9cfcbbf commit da30bc1
Showing 1 changed file with 17 additions and 7 deletions.
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

0 comments on commit da30bc1

Please sign in to comment.