Skip to content

Commit b7803c1

Browse files
authored
Address bugs in format-time.js for 12-hour format
Fix bugs related to formatting time in 12-hour clock.
1 parent 029bd41 commit b7803c1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,30 @@ console.assert(
2323
currentOutput2 === targetOutput2,
2424
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2525
);
26+
27+
// [ChunYanWong] Find the bugs as follows
28+
// Midnight Bug (00:xx): For "00:15", it returns "00:15 am" instead of "12:15 am".
29+
// Noon Bug (12:xx): For "12:35", it hits the else block and returns "12:35 am" instead of "12:35 pm".
30+
// Minutes are Hardcoded: For "16:45", it discards the actual minutes and hardcodes :00 pm, returning "3:00 pm".
31+
32+
//function formatAs12HourClock(time) {
33+
// Guard clause: handle invalid or empty inputs safely
34+
// if (!time || typeof time !== 'string' || !time.includes(':')) {
35+
// return "00:00 am";
36+
// }
37+
38+
// const hours24 = Number(time.slice(0, 2));
39+
// const minutes = time.slice(3, 5); // Preserve actual minutes dynamic input
40+
41+
// Determine am vs pm
42+
// const period = hours24 >= 12 ? "pm" : "am";
43+
44+
// Convert hours to 12-hour format
45+
// let hours12 = hours24 % 12;
46+
// if (hours12 === 0) hours12 = 12; // Adjusts midnight (00) and noon (12) to 12
47+
48+
// Format hours back into a 2-digit padded string
49+
// const paddedHours = String(hours12).padStart(2, "0");
50+
51+
// return `${paddedHours}:${minutes} ${period}`;
52+
//}

0 commit comments

Comments
 (0)