Skip to content

Commit

Permalink
fix: add conditional for minutes calculation so that minutes still pr…
Browse files Browse the repository at this point in the history
…operly shows as :59 until hour is increased by one
  • Loading branch information
KaylaKremer committed Jun 23, 2023
1 parent b88385d commit e746250
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const toHHMM = (input) => {
const sign = total < 0 ? '-' : '';
total = Math.abs(total);
const hours = Math.floor(total / 60);
const minutes = Math.round(total) % 60;
let minutes = total % 60;
if (minutes >= 59.5 && minutes <= 60) {
minutes = Math.floor(minutes);
} else {
minutes = Math.round(minutes);
}
const paddedMinutes = minutes.toString().padStart(2, '0');
return `${sign}${hours}:${paddedMinutes}`;
};
Expand Down

0 comments on commit e746250

Please sign in to comment.