Skip to content

London | 26-ITP-Sep | Alan Mak | Sprint 1 | formatAs12HourClock Coursework - #1641

Open
AlanGit-debug2604 wants to merge 13 commits into
CodeYourFuture:mainfrom
AlanGit-debug2604:Sprint1-Coursework
Open

AlanGit-debug2604 wants to merge 13 commits into
CodeYourFuture:mainfrom
AlanGit-debug2604:Sprint1-Coursework

Conversation

@AlanGit-debug2604

Copy link
Copy Markdown

Alan Mak, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1197

Changelist

Edit lines in timeConverter.js for edge cases within valid inputs. Edit lines in timeConverter.test.js for five additional test cases. All tests run successfully.

Questions

For the purpose of stretching this task, I am researching on time Converter logic other than using if and else if, which produce long chunk of code lines when condition expands. I am wondering the readability for reviewers using key word switch?

@AlanGit-debug2604 AlanGit-debug2604 added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 4, 2026

@abdishakoor-dev abdishakoor-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function now handles all three bugs from the starter: minutes are kept after noon, 12:xx is pm, and 00:xx is 12 am. Testing the hours with one digit and two digits separately (lines 17 and 21) was a good way to look for edge cases.

Three things before I can mark this Complete:

  1. timeConverter.test.js line 10: the expected value of a starter test has changed. See my comment there.
  2. .gitignore is changed in this PR, but it isn't part of the task. See my comment there.
  3. Two edge cases have no test yet. See my comment on timeConverter.test.js line 22.

On your question about switch: a plain switch (hours) compares hours against each case with ===, so it suits exact values like 12 but not ranges like hours > 12. There is a switch (true) pattern that allows ranges, but for conditions like yours most people find if / else if easier to read. I think having fewer branches would help readability more than changing the keyword. My comment on timeConverter.js line 10 is a place to start.

Add the Needs Review label again once you've pushed.

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"), "8:00 am");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The starter expected "08:00 am" here, with the zero. The starter tests describe what the function must return, so they stay as written. Please put back "08:00 am" and run the tests. It will fail, and that's fine: it means timeConverter.js is what needs to change. Then check that line 18 uses the same format.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed two morning time test cases back to starter tests expected results e.g. "08:00am". See changes on line 10 and 18

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ran an initial test after correction, validated two morning time branches need to change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now. Good.

Comment thread .gitignore Outdated
.vscode
**/.DS_Store No newline at end of file
**/.DS_Store
Prep/ No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should only change files in format-clock-edge-cases/. To undo this change, run git checkout main -- .gitignore on your branch, then commit and push. If you want git to ignore your Prep/ folder only on your own computer, you can add it to .git/info/exclude instead. That file is never committed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran undo change, committed, and pushed.

Also added Prep to last line of .git/info/exclude

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gone from the PR now. Thanks.

} else if (hours === 12) {
return `12:${minutes} pm`;
} else if (hours > 9) {
return `${hours}:${minutes} am`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 10 and 14 return the same template. Is there any input that reaches line 10 and would give a different answer if it went to line 14 instead? If not, do you need this branch?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsequent to put back starter tests expecting results (0X:00 am/pm) on single hour scenarios, keep existing branches to distinct where hours >12 (for pm) and hours <=9 (for am).

Also added hours >21 branch to keep 10pm and beyond in place rather than showing 010:00pm. Validated and passed in the first test case in test.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the two branches give different answers now.

});

test("can correctly convert dual characters hour morning time", function () {
assert.equal(formatAs12HourClock("11:00"), "11:00 am");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugs often hide at the exact point where something changes. 11:00 is an hour before am turns into pm. What is the very last minute before that happens? And what is the last minute of the whole day, just before it goes back to am? Each of those is worth its own test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two test cases for edge scenarios: last minutes in each session of the day.

Both tests passed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the two. Good.

});

test("can correctly shows minutes input", function () {
assert.equal(formatAs12HourClock("16:59"), "4:59 pm");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, not needed for Complete: once morning times keep their zero ("08:00 am"), should 16:59 give "4:59 pm" or "04:59 pm"? Whichever you pick, it's worth being the same for am and pm.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep converter and test align to stay result time format the same as 0X:00 for am and pm.

Validated and passed in test file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent now. Good.

@abdishakoor-dev abdishakoor-dev added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 5, 2026
@AlanGit-debug2604 AlanGit-debug2604 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 5, 2026

@abdishakoor-dev abdishakoor-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything from last round is fixed, and you now use the same zero-padded format for am and pm, so the output reads consistently across the day.

Two things left before I can mark it Complete:

  1. timeConverter.test.js lines 29 and 33 are the same test. See my comment there.
  2. A few boundaries still have no test: a time just after midnight, just after noon, and the first minute of the afternoon. See my comment on line 14. I missed these last time, sorry.

Add the Needs Review label again once you've pushed.

assert.equal(formatAs12HourClock("12:00"), "12:00 pm");
});

test("can correctly convert to single character afternoon time", function () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 29 and 33 both call formatAs12HourClock("16:59") and expect the same answer. What does the second one check that the first doesn't? Keep one, or change one to an input that tests something new.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the hour in second test on line 33 - to test minutes input shows correctly.

Test passed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13:30 tests something new. Good.

});

test("can correctly convert midnight time", function () {
assert.equal(formatAs12HourClock("00:00"), "12:00 am");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your 00:00 and 12:00 tests both use 00 minutes. What happens with 00:30 or 12:01? Each goes through a branch that builds the minutes on its own. And 13:00 is the very first time that reaches your hours > 12 branch. Each of those is worth its own test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added additional test cases for last minute of morning, last minute of the day, first minute of the day, and first minute after noon.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests passed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three are there now. Good.

@abdishakoor-dev abdishakoor-dev removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 5, 2026
@AlanGit-debug2604 AlanGit-debug2604 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 5, 2026

@abdishakoor-dev abdishakoor-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three boundaries are tested now, and the duplicate is gone. Your tests cover every point where the clock changes, from 00:01 through to 23:59. Nothing left to do, marking this Complete. Well done.

@abdishakoor-dev abdishakoor-dev added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants