Skip to content

Commit 379bec4

Browse files
committed
added minutes to function
1 parent ce94896 commit 379bec4

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
function formatAs12HourClock(time) {
22
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(3, 5);
34

45
if (hours > 12) {
56
const time = hours - 12;
7+
68
if (time < 10) {
7-
return `0${time}:00 pm`;
9+
return `0${time}:${minutes} pm`;
810
}
9-
return `${hours - 12}:00 pm`;
11+
return `${hours - 12}:${minutes} pm`;
12+
}
13+
if (hours === 0) {
14+
return `12:${minutes} am`;
15+
}
16+
if (hours === 12) {
17+
return `12:${minutes} pm`;
1018
}
1119

1220
if (hours < 10) {
13-
return `0${hours}:00 am`;
21+
return `0${hours}:${minutes} am`;
1422
}
1523

16-
return `${time} am`;
24+
return `${time}: ${minutes} am`;
1725
}
1826

1927
export { formatAs12HourClock };

0 commit comments

Comments
 (0)