Skip to content

Commit b2684a1

Browse files
fix: correct time formatting logic for midnight and noon cases
1 parent b2a5048 commit b2684a1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
77
const minutes=time.slice(3,5)
8-
if(hours<1){
8+
if(hours===0){
99
return `12:${minutes} am`
1010
}
11-
if(hours==12 && minutes==00){
12-
return "12:00 pm"
11+
if(hours===12 ){
12+
return `${hours}:${minutes} pm`
1313
}
1414
if (hours > 12) {
1515
return `${hours - 12}:${minutes} pm`;
@@ -52,8 +52,8 @@ console.assert(
5252
`current output: ${currentOutput5}, target output: ${targetOutput5}`
5353
);
5454

55-
const currentOutput6 = formatAs12HourClock("12:00");
56-
const targetOutput6 = "12:00 pm";
55+
const currentOutput6 = formatAs12HourClock("12:59");
56+
const targetOutput6 = "12:59 pm";
5757
console.assert(
5858
currentOutput6 === targetOutput6,
5959
`current output: ${currentOutput6}, target output: ${targetOutput6}`

0 commit comments

Comments
 (0)