Skip to content

Commit

Permalink
chore: handle 24h for secondsToReadableDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Mar 6, 2024
1 parent 281c81b commit d0dbc13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/date/duration.spec.ts
Expand Up @@ -62,6 +62,10 @@ describe('duration', () => {
expect(secondsToReadableDuration(444444)).toBe('5d 3h');
});

it('handles 24 hours', () => {
expect(secondsToReadableDuration(691200)).toBe('8d');
});

it('handles decimal duration inputs', () => {
expect(secondsToReadableDuration(2565.568)).toBe('43m');
});
Expand Down
4 changes: 4 additions & 0 deletions src/date/duration.ts
Expand Up @@ -56,6 +56,10 @@ export const secondsToReadableDuration = (seconds: number | unknown) => {
(normalizedSeconds - days * (60 * 60 * 24)) / 60 / 60
);

if (hour === 24) {
return `${days + 1}${fDay}`;
}

return `${days}${fDay}${hour > 0 ? ` ${hour}${fHour}` : ''}`;
}

Expand Down

0 comments on commit d0dbc13

Please sign in to comment.