Skip to content

Commit 9722ecb

Browse files
committed
minor improvement
1 parent 1e691bf commit 9722ecb

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/app-components/TimePicker/utils/timeFormatUtils.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,17 @@ export const formatSegmentValue = (value: number | string, segmentType: SegmentT
2929
return value.toString();
3030
}
3131

32-
const numValue = typeof value === 'number' ? value : 0;
33-
32+
let numValue = typeof value === 'number' ? value : Number.parseInt(value, 10);
33+
if (Number.isNaN(numValue)) {
34+
numValue = 0;
35+
}
3436
if (segmentType === 'hours') {
3537
const is12Hour = format.includes('a');
3638
if (is12Hour) {
37-
let displayHour = numValue;
38-
if (displayHour === 0) {
39-
displayHour = 12; // Midnight
40-
} else if (displayHour > 12) {
41-
displayHour -= 12; // PM hours
42-
}
39+
const displayHour = convertTo12HourDisplay(numValue);
4340
return displayHour.toString().padStart(2, '0');
4441
}
4542
}
46-
4743
return numValue.toString().padStart(2, '0');
4844
};
4945

0 commit comments

Comments
 (0)