From ed32fd87b66c71e42a0bbdc62f002cf9637c1a8d Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Sat, 3 Oct 2026 14:55:04 +0100 Subject: [PATCH 1/4] remove extra blank lines in timeConverter.js --- format-clock-edge-cases/timeConverter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..80e134a6c 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -9,3 +9,5 @@ function formatAs12HourClock(time) { } export {formatAs12HourClock}; + + From 2d554c76dd088e64e23682b4fb550e240e021e1b Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Sat, 3 Oct 2026 14:55:14 +0100 Subject: [PATCH 2/4] add test case for converting noon time in timeConverter.test.js --- format-clock-edge-cases/timeConverter.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..144407c00 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -9,3 +9,8 @@ test("correctly convert time after 12:00", function(){ test("can correctly convert morning time", function() { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); + + +test("can correctly convert morning time", function() { + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +}); From b3e50e6c1ee7db8a5e7cac975f07d0f8f7e1819d Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Sat, 3 Oct 2026 14:56:47 +0100 Subject: [PATCH 3/4] refactor timeConverter.js to improve hour formatting logic --- format-clock-edge-cases/timeConverter.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 80e134a6c..f80933a4d 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,13 +1,18 @@ function formatAs12HourClock(time) { + const [hoursStr, minutesStr] = time.split(":"); + let hours = Number(hoursStr); - const hours = Number(time.slice(0, 2)); + const period = hours >= 12 ? "pm" : "am"; - if (hours > 12) { - return `${hours - 12}:00 pm`; + if (hours === 0) { + hours = 12; + } else if (hours > 12) { + hours = hours - 12; } - return `${time} am`; -} -export {formatAs12HourClock}; + const formattedHours = hours.toString().padStart(2, "0"); + return `${formattedHours}:${minutesStr} ${period}`; +} +export { formatAs12HourClock }; \ No newline at end of file From f3850fc0ad1e20fcfd8fe6c82322df19c749c65a Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Sat, 3 Oct 2026 14:58:49 +0100 Subject: [PATCH 4/4] format timeConverter.test.js for consistency and readability --- format-clock-edge-cases/timeConverter.test.js | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 144407c00..290bde463 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,16 +1,27 @@ -import {formatAs12HourClock} from "./timeConverter.js"; +import { formatAs12HourClock } from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; -test("correctly convert time after 12:00", function(){ - assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); +test("correctly convert late evening time", function () { + assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); }); -test("can correctly convert morning time", function() { - assert.equal(formatAs12HourClock("08:00"), "08:00 am"); +test("can correctly convert morning time", function () { + assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); +test("can correctly convert noon", function () { + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +}); + +test("can correctly convert midnight", function () { + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); +}); -test("can correctly convert morning time", function() { - assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +test("preserves non-zero minutes in afternoon", function () { + assert.equal(formatAs12HourClock("13:45"), "01:45 pm"); }); + +test("can correctly convert post-noon minutes", function () { + assert.equal(formatAs12HourClock("12:30"), "12:30 pm"); +}); \ No newline at end of file