From 5225f24b6eebc74189a84865dda732d4fe25b14f Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:30:37 +0100 Subject: [PATCH 1/4] Add minutes variable and write a test to check it --- format-clock-edge-cases/timeConverter.js | 7 ++++--- format-clock-edge-cases/timeConverter.test.js | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..018aa634e 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,12 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); if (hours > 12) { - return `${hours - 12}:00 pm`; + const pmHours = (hours - 12).toString().padStart(2, "0"); + return `${pmHours}:${minutes} 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..f2afb5000 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 minutes", () => + assert.equal(formatAs12HourClock("13:30"), "01:30 pm")); From 2fa8c1465711f8a16cb824957932daccfb3eb4ae Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:48:04 +0100 Subject: [PATCH 2/4] Write tests for hours before midnight and midday --- 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 f2afb5000..feef14da2 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -12,3 +12,9 @@ test("can correctly convert morning time", function () { test("can correctly convert minutes", () => assert.equal(formatAs12HourClock("13:30"), "01:30 pm")); + +test("can correctly convert hours before midnight", () => + assert.equal(formatAs12HourClock("23:59"), "11:59 pm")); + +test("can correctly convert hours before midday", () => + assert.equal(formatAs12HourClock("11:59"), "11:59 am")); From d136f28664cde7851632465777f6bf6cc47f6ba6 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 5 Oct 2026 21:24:13 +0100 Subject: [PATCH 3/4] Write a test and change code to correctly convert midnight --- format-clock-edge-cases/timeConverter.js | 4 +++- format-clock-edge-cases/timeConverter.test.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 018aa634e..46d1d2e36 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -2,7 +2,9 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); const minutes = time.slice(3, 5); - if (hours > 12) { + if (hours === 0) { + return `12:${minutes} am`; + } else if (hours > 12) { const pmHours = (hours - 12).toString().padStart(2, "0"); return `${pmHours}:${minutes} pm`; } diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index feef14da2..c71beef56 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -18,3 +18,6 @@ test("can correctly convert hours before midnight", () => test("can correctly convert hours before midday", () => assert.equal(formatAs12HourClock("11:59"), "11:59 am")); + +test("can correctly convert midnight", () => + assert.equal(formatAs12HourClock("00:00"), "12:00 am")); From 6891773f8a1c9238d4e0acb545fc709b2858e450 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 5 Oct 2026 21:33:10 +0100 Subject: [PATCH 4/4] Write a test and change code to correctly convert midday hours --- format-clock-edge-cases/timeConverter.js | 2 ++ format-clock-edge-cases/timeConverter.test.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 46d1d2e36..250b89c90 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -4,6 +4,8 @@ function formatAs12HourClock(time) { if (hours === 0) { return `12:${minutes} am`; + } else if (hours === 12) { + return `12:${minutes} pm`; } else if (hours > 12) { const pmHours = (hours - 12).toString().padStart(2, "0"); return `${pmHours}:${minutes} pm`; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index c71beef56..7bd09a60e 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -21,3 +21,6 @@ test("can correctly convert hours before midday", () => test("can correctly convert midnight", () => assert.equal(formatAs12HourClock("00:00"), "12:00 am")); + +test("can correctly convert midday", () => + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"));