From b80ce879a46140555202608a12ea813bfd19a14d Mon Sep 17 00:00:00 2001 From: Sakiya Mayow Date: Sat, 3 Oct 2026 16:15:01 +0100 Subject: [PATCH 1/4] if statement added --- format-clock-edge-cases/timeConverter.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..c0baa8132 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,19 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); if (hours > 12) { + const time = hours - 12; + if (time < 10) { + return `0${time}:00 pm`; + } return `${hours - 12}:00 pm`; } + + if (hours < 10) { + return `0${hours}:00 am`; + } + return `${time} am`; } -export {formatAs12HourClock}; +export { formatAs12HourClock }; From 4092ead48f666953ac343f9264cbf423b076d560 Mon Sep 17 00:00:00 2001 From: Sakiya Mayow Date: Sat, 3 Oct 2026 16:15:21 +0100 Subject: [PATCH 2/4] edge cases --- format-clock-edge-cases/timeConverter.test.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..e0457deb3 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,11 +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 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 time after 12:00 ", function () { + assert.equal(formatAs12HourClock("14:00"), "02:00 pm"); +}); + +test("correctly convert time after 12:00 ", function () { + assert.equal(formatAs12HourClock("21:00"), "09:00 pm"); +}); + +test("correctly convert time after 12:00 ", function () { + assert.equal(formatAs12HourClock("16:00"), "04:00 pm"); +}); + +test("correctly convert time after 12:00 ", function () { + assert.equal(formatAs12HourClock("19:00"), "07:00 pm"); }); From ce94896d09cfb07cf8f43f13ed00097d5bff311d Mon Sep 17 00:00:00 2001 From: Sakiya Mayow Date: Mon, 5 Oct 2026 23:47:29 +0100 Subject: [PATCH 3/4] added boundary cases --- 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 e0457deb3..3b08333f4 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -6,7 +6,7 @@ test("correctly convert time after 12:00", function () { assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); }); -test("can correctly convert morning time", function () { +test("can convert morning time from 08:00 to 08:00 am", function () { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); @@ -25,3 +25,11 @@ test("correctly convert time after 12:00 ", function () { test("correctly convert time after 12:00 ", function () { assert.equal(formatAs12HourClock("19:00"), "07:00 pm"); }); + +test("converts 23:59 to 11:59 ", function () { + assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); +}); + +test("converts 12:01 to 12:01 ", function () { + assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); +}); From 379bec4b0eec2d10e9921493b38419b679034cc6 Mon Sep 17 00:00:00 2001 From: Sakiya Mayow Date: Mon, 5 Oct 2026 23:47:56 +0100 Subject: [PATCH 4/4] added minutes to function --- format-clock-edge-cases/timeConverter.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index c0baa8132..42a7d0e55 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,19 +1,27 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); if (hours > 12) { const time = hours - 12; + if (time < 10) { - return `0${time}:00 pm`; + return `0${time}:${minutes} pm`; } - return `${hours - 12}:00 pm`; + return `${hours - 12}:${minutes} pm`; + } + if (hours === 0) { + return `12:${minutes} am`; + } + if (hours === 12) { + return `12:${minutes} pm`; } if (hours < 10) { - return `0${hours}:00 am`; + return `0${hours}:${minutes} am`; } - return `${time} am`; + return `${time}: ${minutes} am`; } export { formatAs12HourClock };