Skip to content

London | 26-ITP-Sep | Shirin Panahian | Sprint 1 | Exhaustively test and fix formatAs12HourClock - #1633

Open
shirinpanahian wants to merge 6 commits into
CodeYourFuture:mainfrom
shirinpanahian:Sprint1-clock-edge-cases
Open

shirinpanahian wants to merge 6 commits into
CodeYourFuture:mainfrom
shirinpanahian:Sprint1-clock-edge-cases

Conversation

@shirinpanahian

Copy link
Copy Markdown

Learners, 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

Fixed formatAs12HourClock to correctly convert 24-hour times to 12-hour format and Added tests for the different edge cases.

@shirinpanahian shirinpanahian added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 1, 2026
Comment thread format-clock-edge-cases/timeConverter.test.js
Comment on lines +3 to 11
if (hours === 0) {
return `${String(hours + 12).padStart(2, "0")}${time.slice(2, 5)} am`;
}
if (hours === 12) {
return `${time} pm`;
}
if (hours > 12) {
return `${hours - 12}:00 pm`;
return `${String(hours - 12).padStart(2, "0")}${time.slice(2, 5)} 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.

  • On line 4: Is it necessary to compute the "hour" part of the constructed string?

  • Could consider storing the minute in a variable first to avoid repeated code.

  • Note: The .slice() method supports negative indices, which count positions from the end of the string.
    For example, str.slice(-3) returns the substring containing last three characters from str.

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.

Line 5 is much simpler now, and the minutes variable removes the repeat. Good.

@cjyuan cjyuan 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 4, 2026
@shirinpanahian shirinpanahian added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 5, 2026
@cjyuan

cjyuan commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Could you also address this comment? #1633 (comment)

@cjyuan cjyuan 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

@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.

Both of the earlier comments are sorted: every hour group now has a single-digit and a double-digit minute test, and storing the minutes once made the midnight line much simpler. One optional naming point inline.

Marking this Complete, well done.

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

test("can correctly convert minutes", 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.

Optional: "can correctly convert minutes" doesn't say what makes 21:08 worth testing. It's the last pm hour that becomes a single digit (9), with a single-digit minute. A name like "can correctly convert the last single-digit pm hour" or "can correctly convert 9pm with single-digit minutes" would say that, the way your other test names do.

@abdishakoor-dev abdishakoor-dev added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 5, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants