From f5569ab622f66ed91a44a9f3a9d04c90bd6c2978 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 21:57:22 +0100 Subject: [PATCH 1/7] Fix midnight edge case --- format-clock-edge-cases/timeConverter.js | 7 +++++-- format-clock-edge-cases/timeConverter.test.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..5039037b7 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,14 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); + if (hours === 0) { + return `12:${time.slice(-2)} am`; + } + if (hours > 12) { return `${hours - 12}:00 pm`; } return `${time} am`; } -export {formatAs12HourClock}; +export { formatAs12HourClock }; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..a783279ed 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,11 +1,14 @@ -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("can correctly convert midnight", () => + assert.equal(formatAs12HourClock("00:00"), "12:00 am")); From 652824337794c48ece5b87c8bdd9d6c780847b6d Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 22:04:48 +0100 Subject: [PATCH 2/7] fix noon edge case --- format-clock-edge-cases/timeConverter.js | 4 ++++ format-clock-edge-cases/timeConverter.test.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 5039037b7..adbddf0be 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -5,6 +5,10 @@ function formatAs12HourClock(time) { return `12:${time.slice(-2)} am`; } + if (hours === 12) { + return `${time} pm`; + } + if (hours > 12) { return `${hours - 12}:00 pm`; } diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index a783279ed..d09fe1c94 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -12,3 +12,6 @@ test("can correctly convert morning time", function () { test("can correctly convert midnight", () => assert.equal(formatAs12HourClock("00:00"), "12:00 am")); + +test("converts noon 12:00", () => + assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); From 7f60bc9e039cda746e96402d499202dfecfdbe0f Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 22:08:16 +0100 Subject: [PATCH 3/7] Test 13:00 conversion --- format-clock-edge-cases/timeConverter.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index d09fe1c94..9119c70ea 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -15,3 +15,6 @@ test("can correctly convert midnight", () => test("converts noon 12:00", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); + +test("converts 13:00", () => + assert.equal(formatAs12HourClock("13:00"), "1:00 pm")); From e47b68e462f4fcd7404821895395834919535f67 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 22:10:36 +0100 Subject: [PATCH 4/7] Test 12:59 conversion --- format-clock-edge-cases/timeConverter.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 9119c70ea..5fb066c8e 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -18,3 +18,6 @@ test("converts noon 12:00", () => test("converts 13:00", () => assert.equal(formatAs12HourClock("13:00"), "1:00 pm")); + +test("converts 12:59", () => + assert.equal(formatAs12HourClock("12:59"), "12:59 pm")); From e4d04ac3b62500b563738c1695e75de63278b994 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 22:15:48 +0100 Subject: [PATCH 5/7] Test 23:59 conversion --- format-clock-edge-cases/timeConverter.js | 2 +- format-clock-edge-cases/timeConverter.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index adbddf0be..0ecde0f35 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -10,7 +10,7 @@ function formatAs12HourClock(time) { } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${time.slice(-2)} pm`; } return `${time} am`; } diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 5fb066c8e..b1ed20a31 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -21,3 +21,6 @@ test("converts 13:00", () => test("converts 12:59", () => assert.equal(formatAs12HourClock("12:59"), "12:59 pm")); + +test("converts 23:59 at night", () => + assert.equal(formatAs12HourClock("23:59"), "11:59 pm")); From 6fc1be11f21efd87b9129698b45a23960c5b932e Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 2 Oct 2026 22:22:04 +0100 Subject: [PATCH 6/7] Test 11:59 before noon --- format-clock-edge-cases/timeConverter.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index b1ed20a31..6c1d854ac 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -24,3 +24,9 @@ test("converts 12:59", () => test("converts 23:59 at night", () => assert.equal(formatAs12HourClock("23:59"), "11:59 pm")); + +test("converts 00:59 after midnight", () => + assert.equal(formatAs12HourClock("00:59"), "12:59 am")); + +test("converts 11:59 before noon", () => + assert.equal(formatAs12HourClock("11:59"), "11:59 am")); From a7e351de4eda5f0f081d870548583bc9a50e6896 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Tue, 6 Oct 2026 20:18:56 +0100 Subject: [PATCH 7/7] Fix consistent time format $ repetition --- format-clock-edge-cases/timeConverter.js | 7 ++++--- format-clock-edge-cases/timeConverter.test.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 0ecde0f35..2ee969cdc 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,8 +1,9 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(-2); if (hours === 0) { - return `12:${time.slice(-2)} am`; + return `12:${minutes} am`; } if (hours === 12) { @@ -10,9 +11,9 @@ function formatAs12HourClock(time) { } if (hours > 12) { - return `${hours - 12}:${time.slice(-2)} pm`; + return `${hours - 12}:${minutes} pm`; } - return `${time} am`; + return `${hours}:${minutes} am`; } export { formatAs12HourClock }; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 6c1d854ac..9d7a5eda4 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -7,7 +7,7 @@ test("correctly convert time after 12:00", function () { }); test("can correctly convert morning time", function () { - assert.equal(formatAs12HourClock("08:00"), "08:00 am"); + assert.equal(formatAs12HourClock("08:00"), "8:00 am"); }); test("can correctly convert midnight", () =>