Skip to content

Commit

Permalink
fix(ui5-timepicker): fix AM/PM selection (#1569)
Browse files Browse the repository at this point in the history
Fix period selection. Previously selecting "PM" results in "AM" within the input field and vice versa.
  • Loading branch information
ilhan007 committed Apr 30, 2020
1 parent 832c34e commit ad923a2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/main/src/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,21 @@ class TimePicker extends UI5Element {
minutesSlider = this.minutesSlider,
hoursSlider = this.hoursSlider,
periodsSlider = this.periodsSlider,
hours = hoursSlider ? hoursSlider.getAttribute("value") : this._hoursParameters.minHour.toString(),
minutes = minutesSlider ? minutesSlider.getAttribute("value") : "0",
seconds = secondsSlider ? secondsSlider.getAttribute("value") : "0",
period = periodsSlider ? periodsSlider.getAttribute("value") : this.periodsArray[0];

if (this._hoursParameters.isTwelveHoursFormat && period === this.periodsArray[0]) {
selectedDate.setHours(hours * 1 + 12);
} else {
selectedDate.setHours(hours);
let hours = hoursSlider ? hoursSlider.getAttribute("value") : this._hoursParameters.minHour.toString();

if (period === this.periodsArray[0]) { // AM
hours = hours === "12" ? 0 : hours;
}

if (period === this.periodsArray[1]) { // PM
hours = hours === "12" ? hours : hours * 1 + 12;
}

selectedDate.setHours(hours);
selectedDate.setMinutes(minutes);
selectedDate.setSeconds(seconds);

Expand Down

0 comments on commit ad923a2

Please sign in to comment.