There was an error while loading. Please reload this page.
1 parent d1cb728 commit 3d03d05Copy full SHA for 3d03d05
1 file changed
format-clock-edge-cases/timeConverter.js
@@ -1,11 +1,18 @@
1
function formatAs12HourClock(time) {
2
-
3
const hours = Number(time.slice(0, 2));
+ const minutes = time.slice(-2);
4
5
- if (hours > 12) {
6
- return `${hours - 12}:00 pm`;
+ if (hours > 24 || hours < 0) {
+ return "invalid input.";
7
+ } else if (hours === 24 || hours === 0) {
8
+ return `${12}:${minutes}am`;
9
+ } else if (hours === 12) {
10
+ return `${hours}:${minutes}pm`;
11
+ } else if (hours > 12) {
12
+ return `${hours - 12}:${minutes}pm`;
13
+ } else {
14
+ return `${hours}:${minutes}am`;
15
+ }
16
}
- return `${time} am`;
-}
17
-export {formatAs12HourClock};
18
+export { formatAs12HourClock };
0 commit comments