Skip to content

Commit

Permalink
fix: return +1000d for long ms on ETA
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioislima committed Oct 31, 2024
1 parent 2d80864 commit e370747
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperplay/utils",
"version": "0.3.0",
"version": "0.3.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/getEtaAndBytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('getETAStringFromMs', () => {
test('should return "1d" for 90000000 milliseconds', () => {
expect(getETAStringFromMs(1000 * 60 * 60 * 24 + 1000 * 60 * 60)).toBe('1d')
})
test('should return "+1000d" if the ETA is over 1000 days', () => {
expect(getETAStringFromMs(86500000000)).toBe('+1000d')
})
})

describe('calculateEtaFromBytes', () => {
Expand All @@ -42,6 +45,10 @@ describe('calculateEtaFromBytes', () => {
expect(calculateEtaFromBytes(1000, 10, 5500000000)).toBe('6d')
})

test('should return "+1000d" if the ETA is over 1000 days', () => {
expect(calculateEtaFromBytes(1000, 1, 100000000000000)).toBe('+1000d')
})

test('should return null for infinite remaining seconds', () => {
expect(calculateEtaFromBytes(0, 0, 10000)).toBeNull()
})
Expand Down
3 changes: 3 additions & 0 deletions src/getEtaAndBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function getETAStringFromMs(etaInMs: number) {
const days = Math.floor(totalSeconds / 86400)

if (days > 0) {
if (days > 1000) {
return '+1000d'
}
return `${days}d`
} else if (hours > 0) {
return `${hours}h:${minutes}m`
Expand Down

0 comments on commit e370747

Please sign in to comment.