Skip to content

Commit a87db9c

Browse files
committed
Fix time formatting in formatAs12HourClock function
1 parent 3e84b2c commit a87db9c

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
function formatAs12HourClock(time) {
22

33
const hours = Number(time.slice(0, 2));
4+
const minutes = time.slice(3);
5+
6+
if (hours === 12) {
7+
return `12:${minutes}pm`;
8+
}
9+
10+
if (hours === 0) {
11+
return `12:${minutes}am`;
12+
}
413

514
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
15+
return `${hours - 12}:${minutes}pm`;
16+
717
}
8-
return `${time} am`;
18+
return `${time}am`;
919
}
20+
console.log(formatAs12HourClock("00:00"))
1021

1122
export {formatAs12HourClock};
23+

0 commit comments

Comments
 (0)