Skip to content

Commit af9ff8a

Browse files
authored
fix(ui5-datetime-picker): fix AM/PM selection (#1551)
FIXES: #1530
1 parent b7e5768 commit af9ff8a

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

packages/main/src/DateTimePicker.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ class DateTimePicker extends DatePicker {
558558
// the time set in the timepicker
559559
const selectedTime = new Date();
560560
const timeValues = await this.getTimePickerValues();
561+
561562
selectedTime.setHours(timeValues.hours);
562563
selectedTime.setMinutes(timeValues.minutes);
563564
selectedTime.setSeconds(timeValues.seconds);
@@ -590,7 +591,14 @@ class DateTimePicker extends DatePicker {
590591
const minutes = minutesSlider ? minutesSlider.value : "0";
591592
const seconds = secondsSlider ? secondsSlider.value : "0";
592593
const period = periodsSlider ? periodsSlider.value : this.periodsArray[0];
593-
hours = period === this.periodsArray[1] ? hours * 1 + 12 : hours;
594+
595+
if (period === this.periodsArray[0]) { // AM
596+
hours = hours === "12" ? 0 : hours;
597+
}
598+
599+
if (period === this.periodsArray[1]) { // PM
600+
hours = hours === "12" ? hours : hours * 1 + 12;
601+
}
594602

595603
return {
596604
hours,
@@ -659,7 +667,7 @@ class DateTimePicker extends DatePicker {
659667

660668
if (config.isTwelveHoursFormat) {
661669
if (config.minHour === 1) {
662-
periodsSlider.value = hours > config.maxHour ? this.periodsArray[1] : this.periodsArray[0];
670+
periodsSlider.value = hours >= config.maxHour ? this.periodsArray[1] : this.periodsArray[0];
663671
} else {
664672
periodsSlider.value = (hours > config.maxHour || hours === config.minHour) ? this.periodsArray[1] : this.periodsArray[0];
665673
}

packages/main/test/pages/DateTimePicker.html

+14
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@
111111
<ui5-input id="input4" style="width: 300px"></ui5-input>
112112
</section>
113113

114+
<section>
115+
<ui5-datetime-picker
116+
id="dtTest12AM"
117+
format-pattern="dd/MM/yyyy, hh:mm:ss aa"
118+
value="13/04/2020, 03:16:16 AM"
119+
></ui5-datetime-picker>
120+
</section>
121+
<ui5-datetime-picker
122+
id="dtTest12PM"
123+
format-pattern="dd/MM/yyyy, hh:mm:ss aa"
124+
value="13/04/2020, 03:16:16 AM"
125+
></ui5-datetime-picker>
126+
</section>
127+
114128
<section>
115129
<ui5-title wrap>DateTimePicker states</ui5-title>
116130
<ui5-datetime-picker value-state="Error"></ui5-datetime-picker>

packages/main/test/specs/DateTimePicker.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,43 @@ describe("DateTimePicker general interaction", () => {
173173

174174
closePickerById("dt");
175175
});
176+
177+
it("tests selection of 12:00:00 AM", () => {
178+
const dtPicker = browser.$("#dtTest12AM");
179+
180+
// act
181+
openPickerById("dtTest12AM");
182+
browser.pause(500);
183+
184+
const picker = getPicker("dtTest12AM");
185+
picker.$(".ui5-dt-hours-wheel").setProperty("value","12");
186+
picker.$(".ui5-dt-minutes-wheel").setProperty("value","00");
187+
picker.$(".ui5-dt-seconds-wheel").setProperty("value","00");
188+
picker.$(".ui5-dt-periods-wheel").setProperty("value","AM");
189+
picker.$("#ok").click();
190+
browser.pause(500);
191+
192+
// assert
193+
const newValue = dtPicker.shadow$("ui5-input").getValue();
194+
assert.strictEqual(newValue.toUpperCase(), "13/04/2020, 12:00:00 AM", "The new date/time is correctly selected.");
195+
});
196+
197+
it("tests selection of 12:00:00 PM", () => {
198+
const dtPicker = browser.$("#dtTest12PM");
199+
200+
// act
201+
openPickerById("dtTest12PM");
202+
browser.pause(500);
203+
204+
const picker = getPicker("dtTest12PM");
205+
picker.$(".ui5-dt-hours-wheel").setProperty("value","12");
206+
picker.$(".ui5-dt-minutes-wheel").setProperty("value","00");
207+
picker.$(".ui5-dt-seconds-wheel").setProperty("value","00");
208+
picker.$(".ui5-dt-periods-wheel").setProperty("value","PM");
209+
picker.$("#ok").click();
210+
211+
// assert
212+
const newValue = dtPicker.shadow$("ui5-input").getValue();
213+
assert.strictEqual(newValue.toUpperCase(), "13/04/2020, 12:00:00 PM", "The new date/time is correctly selected.");
214+
});
176215
});

0 commit comments

Comments
 (0)