From 58741a880aaccb9e96de277b24307aad5d4011db Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 11:44:00 +0100 Subject: [PATCH 01/17] Add test to convert noon time, "12:00" (which fails) --- format-clock-edge-cases/timeConverter.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..1318da41b 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -9,3 +9,5 @@ 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 noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")) From 53b309b4b318b55cbc7e633a6b4efd6e8f154250 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 12:05:52 +0100 Subject: [PATCH 02/17] Refactor the previous test funcs to use arrow funcs --- format-clock-edge-cases/timeConverter.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 1318da41b..eb957de5f 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,12 +2,8 @@ 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", () => 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", () => assert.equal(formatAs12HourClock("08:00"), "08:00 am")); -test("can correctly convert noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")) +test("can correctly convert noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); From 6e1e485e23e35b0561f9f8dd17c624dda401c03f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 12:08:06 +0100 Subject: [PATCH 03/17] Add else clause to function to properly format noon time --- 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..681c808e8 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -4,6 +4,8 @@ function formatAs12HourClock(time) { if (hours > 12) { return `${hours - 12}:00 pm`; + } else if (hours === 12){ + return `${time} pm`; } return `${time} am`; } From c0c27ea13a9e41e11dd66538b8c8e4a11b01d329 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 12:11:37 +0100 Subject: [PATCH 04/17] Add test for time with minutes other than 00, (it fails) --- format-clock-edge-cases/timeConverter.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index eb957de5f..5a078273f 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -7,3 +7,5 @@ test("correctly convert time after 12:00", () => assert.equal(formatAs12HourCloc test("can correctly convert morning time", () => assert.equal(formatAs12HourClock("08:00"), "08:00 am")); test("can correctly convert noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); + +test("can format afternoon time with minutes other than 00", () => assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); From 99591dec6ea1cd02b6cc041859df99bf32890f46 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 12:44:50 +0100 Subject: [PATCH 05/17] Add possible preceding 0 and exact minutes to times after noon --- format-clock-edge-cases/timeConverter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 681c808e8..687cfce20 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -3,7 +3,7 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12 < 10 ? "0" : ""}${hours - 12}:${time.slice(-2)} pm`; } else if (hours === 12){ return `${time} pm`; } From 891851bb986e70f839b56bc7a0a8ea0fc65fccef Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 16:28:37 +0100 Subject: [PATCH 06/17] Add test for morning time complex mins (it passes) --- format-clock-edge-cases/timeConverter.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 5a078273f..398412799 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -9,3 +9,5 @@ test("can correctly convert morning time", () => assert.equal(formatAs12HourCloc test("can correctly convert noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); test("can format afternoon time with minutes other than 00", () => assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); + +test("can format morning time with complex minutes", () => assert.equal(formatAs12HourClock("08:25"), "08:25 am")); From 8c42ec0ae00d4f283a5ddde5c2d4b0bd592c9239 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 16:31:18 +0100 Subject: [PATCH 07/17] Add test for early noon complex minutes (it passes) --- format-clock-edge-cases/timeConverter.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 398412799..220e5acc8 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -11,3 +11,5 @@ test("can correctly convert noon time", () => assert.equal(formatAs12HourClock(" test("can format afternoon time with minutes other than 00", () => assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); test("can format morning time with complex minutes", () => assert.equal(formatAs12HourClock("08:25"), "08:25 am")); + +test("can format early noon complex minutes", () => assert.equal(formatAs12HourClock("12:17"), "12:17 pm")); From 72e8b26bfa66485e2484badc8ad32757e3f53d7e Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 16:34:09 +0100 Subject: [PATCH 08/17] Add test for time between midnight and 1 am (it fails) --- format-clock-edge-cases/timeConverter.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 220e5acc8..8cc8e4768 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -13,3 +13,5 @@ test("can format afternoon time with minutes other than 00", () => assert.equal( test("can format morning time with complex minutes", () => assert.equal(formatAs12HourClock("08:25"), "08:25 am")); test("can format early noon complex minutes", () => assert.equal(formatAs12HourClock("12:17"), "12:17 pm")); + +test("can format between midnight and 1 am", () => assert.equal(formatAs12HourClock("00:15"), "12:15 am")); From ebfc7592e33712a468c06e1434ca8b54c0a57eb4 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 16:36:58 +0100 Subject: [PATCH 09/17] Add else if for when hour = 0, now the final test passes --- 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 687cfce20..0e63d821d 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -6,6 +6,8 @@ function formatAs12HourClock(time) { return `${hours - 12 < 10 ? "0" : ""}${hours - 12}:${time.slice(-2)} pm`; } else if (hours === 12){ return `${time} pm`; + } else if (hours === 0){ + return `12:${time.slice(-2)} am`; } return `${time} am`; } From 7a51317ca038deedcb52c6e745330b1968c7237d Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 17:07:51 +0100 Subject: [PATCH 10/17] Reformatted with prettier --- format-clock-edge-cases/timeConverter.js | 7 +++--- format-clock-edge-cases/timeConverter.test.js | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 0e63d821d..10a755c1f 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,15 +1,14 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); if (hours > 12) { return `${hours - 12 < 10 ? "0" : ""}${hours - 12}:${time.slice(-2)} pm`; - } else if (hours === 12){ + } else if (hours === 12) { return `${time} pm`; - } else if (hours === 0){ + } else if (hours === 0) { return `12:${time.slice(-2)} am`; } 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 8cc8e4768..195e306a8 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,17 +1,24 @@ -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", () => assert.equal(formatAs12HourClock("23:00"), "11:00 pm")); +test("correctly convert time after 12:00", () => + assert.equal(formatAs12HourClock("23:00"), "11:00 pm")); -test("can correctly convert morning time", () => assert.equal(formatAs12HourClock("08:00"), "08:00 am")); +test("can correctly convert morning time", () => + assert.equal(formatAs12HourClock("08:00"), "08:00 am")); -test("can correctly convert noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); +test("can correctly convert noon time", () => + assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); -test("can format afternoon time with minutes other than 00", () => assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); +test("can format afternoon time with minutes other than 00", () => + assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); -test("can format morning time with complex minutes", () => assert.equal(formatAs12HourClock("08:25"), "08:25 am")); +test("can format morning time with complex minutes", () => + assert.equal(formatAs12HourClock("08:25"), "08:25 am")); -test("can format early noon complex minutes", () => assert.equal(formatAs12HourClock("12:17"), "12:17 pm")); +test("can format early noon complex minutes", () => + assert.equal(formatAs12HourClock("12:17"), "12:17 pm")); -test("can format between midnight and 1 am", () => assert.equal(formatAs12HourClock("00:15"), "12:15 am")); +test("can format between midnight and 1 am", () => + assert.equal(formatAs12HourClock("00:15"), "12:15 am")); From 2c2978967d37fa7c34c06d44295ede1ccdae33df Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Mon, 28 Sep 2026 21:52:32 +0100 Subject: [PATCH 11/17] Rephrase test messages so they are more consistent --- format-clock-edge-cases/timeConverter.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 195e306a8..6f618a722 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,23 +2,23 @@ import { formatAs12HourClock } from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; -test("correctly convert time after 12:00", () => +test("can format time after 12:00", () => assert.equal(formatAs12HourClock("23:00"), "11:00 pm")); -test("can correctly convert morning time", () => +test("can format morning time", () => assert.equal(formatAs12HourClock("08:00"), "08:00 am")); -test("can correctly convert noon time", () => +test("can format noon time", () => assert.equal(formatAs12HourClock("12:00"), "12:00 pm")); test("can format afternoon time with minutes other than 00", () => assert.equal(formatAs12HourClock("15:45"), "03:45 pm")); -test("can format morning time with complex minutes", () => +test("can format morning time with minutes other than 00", () => assert.equal(formatAs12HourClock("08:25"), "08:25 am")); -test("can format early noon complex minutes", () => +test("can format early noon with minutes other than 00", () => assert.equal(formatAs12HourClock("12:17"), "12:17 pm")); -test("can format between midnight and 1 am", () => +test("can format time between midnight and 1 am", () => assert.equal(formatAs12HourClock("00:15"), "12:15 am")); From e231337d5b00b818ecba8972a01329522934d6b6 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sat, 3 Oct 2026 15:34:19 +0100 Subject: [PATCH 12/17] Refactor the code to have separate if statements for hours and period. Only return once at the end --- format-clock-edge-cases/timeConverter.js | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 10a755c1f..6f8871e21 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,14 +1,25 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(-2); - if (hours > 12) { - return `${hours - 12 < 10 ? "0" : ""}${hours - 12}:${time.slice(-2)} pm`; - } else if (hours === 12) { - return `${time} pm`; - } else if (hours === 0) { - return `12:${time.slice(-2)} am`; + let period = ""; + let hourString = ""; + + if (hours <= 11){ + period = "am"; + } else { + period = "pm"; + } + + if (hours >= 13){ + hourString = hours - 12 < 10 ? `0${hours - 12}` : `${hours -12}`; + } else if (hours === 0){ + hourString = `${hours + 12}`; + } else { + hourString = hours < 10 ? `0${hours}`:`${hours}`; } - return `${time} am`; + + return `${hourString}:${minutes} ${period}` } export { formatAs12HourClock }; From 6f21d29eacb1be92aed56f41fce32c568a25ad2a Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 4 Oct 2026 17:10:02 +0100 Subject: [PATCH 13/17] Add test for exactly midnight (passes) --- 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 6f618a722..6117819d8 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -22,3 +22,6 @@ test("can format early noon with minutes other than 00", () => test("can format time between midnight and 1 am", () => assert.equal(formatAs12HourClock("00:15"), "12:15 am")); + +test("can format exactly midnight", () => + assert.equal(formatAs12HourClock("00:00"), "12:00 am")); From 461f54bccf75dcca5f4af4e771385b2818ec86ac Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 4 Oct 2026 17:11:35 +0100 Subject: [PATCH 14/17] Add test for last minute before noon (it passes) --- 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 6117819d8..5ebe08563 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -25,3 +25,6 @@ test("can format time between midnight and 1 am", () => test("can format exactly midnight", () => assert.equal(formatAs12HourClock("00:00"), "12:00 am")); + +test("can format last minute before noon", () => + assert.equal(formatAs12HourClock("11:59"), "11:59 am")); \ No newline at end of file From 1ddd30685ff26a9070a02ccb2fe7b134d8bd6b2f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 4 Oct 2026 17:13:44 +0100 Subject: [PATCH 15/17] Add test for last minute before midnight (it passes) --- format-clock-edge-cases/timeConverter.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 5ebe08563..e934d4161 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -27,4 +27,7 @@ test("can format exactly midnight", () => assert.equal(formatAs12HourClock("00:00"), "12:00 am")); test("can format last minute before noon", () => - assert.equal(formatAs12HourClock("11:59"), "11:59 am")); \ No newline at end of file + assert.equal(formatAs12HourClock("11:59"), "11:59 am")); + +test("can format last minute before midnight", () => + assert.equal(formatAs12HourClock("23:59"), "11:59 pm")); From 04df6ca384d4d8c2ee07d98c9c8674c9ff33481a Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 4 Oct 2026 17:15:16 +0100 Subject: [PATCH 16/17] Add test for first time hour >= 13 (it passes) --- 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 e934d4161..fd8eaaa7c 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -31,3 +31,6 @@ test("can format last minute before noon", () => test("can format last minute before midnight", () => assert.equal(formatAs12HourClock("23:59"), "11:59 pm")); + +test("can format first time hour >= 13", () => + assert.equal(formatAs12HourClock("13:00"), "01:00 pm")); From babce7a20b8abed6af1afb0ef7dd362ab0fed982 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Sun, 4 Oct 2026 17:16:01 +0100 Subject: [PATCH 17/17] Format with prettier --- format-clock-edge-cases/timeConverter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 6f8871e21..50347d7f0 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -5,21 +5,21 @@ function formatAs12HourClock(time) { let period = ""; let hourString = ""; - if (hours <= 11){ + if (hours <= 11) { period = "am"; } else { period = "pm"; } - if (hours >= 13){ - hourString = hours - 12 < 10 ? `0${hours - 12}` : `${hours -12}`; - } else if (hours === 0){ + if (hours >= 13) { + hourString = hours - 12 < 10 ? `0${hours - 12}` : `${hours - 12}`; + } else if (hours === 0) { hourString = `${hours + 12}`; } else { - hourString = hours < 10 ? `0${hours}`:`${hours}`; + hourString = hours < 10 ? `0${hours}` : `${hours}`; } - return `${hourString}:${minutes} ${period}` + return `${hourString}:${minutes} ${period}`; } export { formatAs12HourClock };