Skip to content

Commit 7d47a35

Browse files
committed
Fix review feedback on 12-hour clock formatting function
1 parent 3fcfa2e commit 7d47a35

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
function formatAs12HourClock(time) {
2-
const timeParts = time.split(":");
3-
const mins = timeParts[1].padStart(2, "0");
4-
const hoursInt = Number(timeParts[0]);
5-
if (hoursInt === 0) return `${12}:${mins} am`;
6-
if (hoursInt < 12) return `${timeParts[0].padStart(2, "0")}:${mins} am`;
7-
if (hoursInt === 12)
8-
return `${timeParts[0]}:${timeParts[1].padStart(2, "0")} pm`;
2+
const [hours, minutes] = time.split(":");
3+
const mins = minutes.padStart(2, "0");
4+
const hoursInt = Number(hours);
5+
if (hoursInt === 0) {
6+
return `${12}:${mins} am`;
7+
}
8+
if (hoursInt < 12) {
9+
return `${hours.padStart(2, "0")}:${mins} am`;
10+
}
11+
if (hoursInt === 12) {
12+
return `${hours}:${mins} pm`;
13+
}
914
return `${(hoursInt - 12).toString().padStart(2, "0")}:${mins} pm`;
1015
}
1116

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"keywords": [],
1010
"author": "Code Your Future",
1111
"license": "ISC",
12-
"dependencies": {
13-
"jest": "^29.7.0"
12+
"devDependencies": {
13+
"jest": "^30.4.2"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)