From d90021c9159fe6488842de355f91c0c146af0106 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Thu, 15 Oct 2026 18:14:00 +0100 Subject: [PATCH 1/3] add more tests --- format-clock-edge-cases/timeConverter.test.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..cabbfe217 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,11 +1,23 @@ -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 time after 12:00", 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("correctly convert noon", function () { + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +}); + +test("correctly convert midnight", function () { + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); +}); + +test("preserves minutes in afternoon times", function () { + assert.equal(formatAs12HourClock("13:45"), "01:45 pm"); }); From 4c0993b2b4cf5af6f7f23dc4c3746127a0977320 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Thu, 15 Oct 2026 18:46:09 +0100 Subject: [PATCH 2/3] fix error --- format-clock-edge-cases/timeConverter.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index cabbfe217..694579fe1 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -19,5 +19,13 @@ test("correctly convert midnight", function () { }); test("preserves minutes in afternoon times", function () { - assert.equal(formatAs12HourClock("13:45"), "01:45 pm"); + assert.equal(formatAs12HourClock("13:45"), "1:45 pm"); +}); + +test("correctly converts 13:00", function () { + assert.equal(formatAs12HourClock("13:00"), "1:00 pm"); +}); + +test("correctly converts 11:00", function () { + assert.equal(formatAs12HourClock("11:00"), "11:00 am"); }); From 42a5ebc8175bde4c39e5fbfa10054ee6a0928ae0 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Thu, 15 Oct 2026 18:46:41 +0100 Subject: [PATCH 3/3] complete timeConverter.js ex --- format-clock-edge-cases/timeConverter.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..cab379c44 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,17 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3); + if (hours === 0) { + return `12:${minutes} am`; + } + if (hours === 12) { + return `${time} pm`; + } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${minutes} pm`; } return `${time} am`; } -export {formatAs12HourClock}; +export { formatAs12HourClock };