Skip to content

Commit df0add4

Browse files
authored
fix(ui5-timepicker): adjust hours in 12hours format only (#1752)
Consider AM/PM periods in determining hours when 12h format is set, there is no need to adjust the hours in 24hours format. Previously we used to recalculate the hours for both formats, leading to a bug in 24hours format. FIXES: #1714
1 parent a28f201 commit df0add4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/main/src/TimePicker.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,19 @@ class TimePicker extends UI5Element {
511511
periodsSlider = this.periodsSlider,
512512
minutes = minutesSlider ? minutesSlider.getAttribute("value") : "0",
513513
seconds = secondsSlider ? secondsSlider.getAttribute("value") : "0",
514-
period = periodsSlider ? periodsSlider.getAttribute("value") : this.periodsArray[0];
514+
period = periodsSlider ? periodsSlider.getAttribute("value") : this.periodsArray[0],
515+
isTwelveHoursFormat = this._hoursParameters.isTwelveHoursFormat;
515516

516517
let hours = hoursSlider ? hoursSlider.getAttribute("value") : this._hoursParameters.minHour.toString();
517518

518-
if (period === this.periodsArray[0]) { // AM
519-
hours = hours === "12" ? 0 : hours;
520-
}
519+
if (isTwelveHoursFormat) {
520+
if (period === this.periodsArray[0]) { // AM
521+
hours = hours === "12" ? 0 : hours;
522+
}
521523

522-
if (period === this.periodsArray[1]) { // PM
523-
hours = hours === "12" ? hours : hours * 1 + 12;
524+
if (period === this.periodsArray[1]) { // PM
525+
hours = hours === "12" ? hours : hours * 1 + 12;
526+
}
524527
}
525528

526529
selectedDate.setHours(hours);

packages/main/test/pages/TimePicker.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
<ui5-timepicker id="timepicker" format-pattern="HH:mm:ss"></ui5-timepicker>
2424
<ui5-timepicker id="timepicker2" format-pattern="hh:mm:ss" value=""></ui5-timepicker>
2525
<ui5-timepicker id="timepicker3" format-pattern="hh:mm:ss a"></ui5-timepicker>
26-
<ui5-timepicker id="timepicker3" format-pattern="HH:mm"></ui5-timepicker>
26+
<ui5-timepicker id="timepicker4" format-pattern="HH:mm" value="12:05"></ui5-timepicker>
27+
<ui5-timepicker id="timepicker5" format-pattern="hh:mm:ss" value="12:00:01"></ui5-timepicker>
2728
<br>
2829
<ui5-timepicker style="width:100%"></ui5-timepicker>
2930

0 commit comments

Comments
 (0)