Skip to content

Commit ad923a2

Browse files
authored
fix(ui5-timepicker): fix AM/PM selection (#1569)
Fix period selection. Previously selecting "PM" results in "AM" within the input field and vice versa.
1 parent 832c34e commit ad923a2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/main/src/TimePicker.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,21 @@ class TimePicker extends UI5Element {
493493
minutesSlider = this.minutesSlider,
494494
hoursSlider = this.hoursSlider,
495495
periodsSlider = this.periodsSlider,
496-
hours = hoursSlider ? hoursSlider.getAttribute("value") : this._hoursParameters.minHour.toString(),
497496
minutes = minutesSlider ? minutesSlider.getAttribute("value") : "0",
498497
seconds = secondsSlider ? secondsSlider.getAttribute("value") : "0",
499498
period = periodsSlider ? periodsSlider.getAttribute("value") : this.periodsArray[0];
500499

501-
if (this._hoursParameters.isTwelveHoursFormat && period === this.periodsArray[0]) {
502-
selectedDate.setHours(hours * 1 + 12);
503-
} else {
504-
selectedDate.setHours(hours);
500+
let hours = hoursSlider ? hoursSlider.getAttribute("value") : this._hoursParameters.minHour.toString();
501+
502+
if (period === this.periodsArray[0]) { // AM
503+
hours = hours === "12" ? 0 : hours;
505504
}
505+
506+
if (period === this.periodsArray[1]) { // PM
507+
hours = hours === "12" ? hours : hours * 1 + 12;
508+
}
509+
510+
selectedDate.setHours(hours);
506511
selectedDate.setMinutes(minutes);
507512
selectedDate.setSeconds(seconds);
508513

0 commit comments

Comments
 (0)