Skip to content

Commit

Permalink
🐛 Fixed total duration displaying incorrect time
Browse files Browse the repository at this point in the history
  • Loading branch information
gBasil committed Mar 4, 2023
1 parent 388a079 commit b3d0619
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/utils/client/formatSecondsString.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const s = (i: number, string: string) => `${i} ${string}${i === 1 ? '' : 's'}`;

function formatSeconds(seconds: number): string {
const day = Math.floor(seconds / (3600 * 24));
const hr = Math.floor(seconds / 3600);
const min = Math.floor(seconds % 3600 / 60);
const sec = Math.floor(seconds % 3600 % 60);
const days = Math.floor(seconds / 60 / 60 / 24);
const hoursInDay = Math.floor(seconds / 60 / 60 % 24);
const hr = Math.floor(seconds / 60 / 60);
const min = Math.floor(seconds / 60);
const sec = Math.floor(seconds);

if (day > 0) return s(sec, 'day');
if (hr > 0) return s(hr, 'hour');
if (min > 0) return s(min, 'minute');
if (days > 0) return s(days, 'day') + ' and ' + s(hoursInDay, 'hour');
if (hr > 0) return s(hr, 'hour');
if (min > 0) return s(min, 'minute');
if (sec > 0) return s(sec, 'second');
return s(sec, 'second');
}

Expand Down

0 comments on commit b3d0619

Please sign in to comment.