Skip to content

Commit a21732b

Browse files
committed
updated function to include midnight and half hour time conversion
1 parent dbad16a commit a21732b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
function formatAs12HourClock(time) {
2-
32
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(3, 5);
44

5-
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
5+
if (hours === 0) {
6+
return `12:${minutes} am`;
7+
} else if (hours > 12) {
8+
return `${hours - 12}:${minutes} pm`;
9+
} else if (hours === 12) {
10+
return `12:${minutes} pm`;
11+
} else {
12+
return `${time} am`;
713
}
8-
return `${time} am`;
914
}
1015

11-
export {formatAs12HourClock};
16+
export { formatAs12HourClock };

0 commit comments

Comments
 (0)