Repository navigation
London | 26-ITP-Sep | Chandramani Gaire | Sprint 1 | Exhaustively test and fix formatAs12HourClock #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gaireprakash20-ops
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
gaireprakash20-ops:Sprint-1-coursework-of-data-structuring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
London | 26-ITP-Sep | Chandramani Gaire | Sprint 1 | Exhaustively test and fix formatAs12HourClock #1649
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e631272
Remove the redundant code
gaireprakash20-ops 96b65cf
Formate change as per pre section instructions
gaireprakash20-ops 3ae7c4f
make a function which run all the test cases
gaireprakash20-ops a980d4f
make a edge cases .
gaireprakash20-ops a493198
1.js
gaireprakash20-ops c298439
Remove the unnecessary code
gaireprakash20-ops 0aa80bd
Delete unused line
gaireprakash20-ops 8d02c00
test noon midnight and last minutes
gaireprakash20-ops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,17 @@ | ||
| function formatAs12HourClock(time) { | ||
|
|
||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(-3); | ||
|
|
||
| if (hours === 0) { | ||
| return `12${minutes} am`; | ||
| } | ||
| if (hours === 12) { | ||
| return `${time} pm`; | ||
| } | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| return `${String(hours - 12).padStart(2, "0")}${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
| } | ||
|
|
||
| export {formatAs12HourClock}; | ||
| export { formatAs12HourClock }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,43 @@ | ||
| 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 midnight with double digit minutes", function () { | ||
| assert.equal(formatAs12HourClock("00:25"), "12:25 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert noon with the double digits minutes ", function () { | ||
| assert.equal(formatAs12HourClock("12:20"), "12:20 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert evening with single-digit minutes", function () { | ||
| assert.equal(formatAs12HourClock("23:05"), "11:05 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert one minute before noon", function () { | ||
| assert.equal(formatAs12HourClock("11:59"), "11:59 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert one hour after noon", function () { | ||
| assert.equal(formatAs12HourClock("13:00"), "01:00 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert midnight", function () { | ||
| assert.equal(formatAs12HourClock("00:00"), "12:00 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert Noon", function () { | ||
| assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert last minutes of the day", function () { | ||
| assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests a time inside the midnight hour, which is good. What about midnight itself,
"00:00"? The same goes for noon,"12:00", and the very last minute of the day,"23:59". Bugs often hide at the exact point where something changes, so each of those is worth its own test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All three are in now. Good.