Skip to content

Commit 23a25ca

Browse files
committed
fix: correct time formatting for 12 PM and update edge case test
1 parent f7c0a35 commit 23a25ca

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
77
const minutes = time.slice(3, 5);
88
if (hours >= 12) {
9-
return `${hours - 12}:${minutes} pm`;
9+
return `${hours !== 12 ? hours - 12 : hours}:${minutes} pm`;
1010
}
1111
return `${time} am`;
1212
}
@@ -90,8 +90,8 @@ console.assert(
9090
);
9191

9292
// Edge: single digit hour
93-
const outSingle = formatAs12HourClock("7:00");
94-
const targetSingle = "7:00 am";
93+
const outSingle = formatAs12HourClock("7:45");
94+
const targetSingle = "7:45 am";
9595
console.assert(
9696
outSingle === targetSingle,
9797
`current output: ${outSingle}, target output: ${targetSingle}`

0 commit comments

Comments
 (0)