This commit is contained in:
Eldar Dadashov 2026-06-26 00:03:08 +03:00 committed by GitHub
commit 00e96d6444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -64,6 +64,9 @@ describe('formatFileSize', () => {
it('should format petabytes correctly', () => {
expect(formatFileSize(1500000000000000)).toBe('1.33 PB')
})
it('should clamp to PB instead of an undefined unit for very large sizes', () => {
expect(formatFileSize(1024 ** 6)).toBe('1024.00 PB')
})
})
describe('formatTime', () => {
it('should return the input if it is falsy', () => {
@ -81,6 +84,9 @@ describe('formatTime', () => {
it('should handle large numbers', () => {
expect(formatTime(7200)).toBe('2.00 h')
})
it('should clamp to hours instead of an undefined unit for very large durations', () => {
expect(formatTime(216000)).toBe('60.00 h')
})
})
describe('formatNumberAbbreviated', () => {
it('should return number as string when less than 1000', () => {

View File

@ -75,7 +75,7 @@ export const formatFileSize = (fileSize: number) => {
return fileSize
const units = ['', 'K', 'M', 'G', 'T', 'P']
let index = 0
while (fileSize >= 1024 && index < units.length) {
while (fileSize >= 1024 && index < units.length - 1) {
fileSize = fileSize / 1024
index++
}
@ -94,7 +94,7 @@ export const formatTime = (seconds: number) => {
return seconds
const units = ['sec', 'min', 'h']
let index = 0
while (seconds >= 60 && index < units.length) {
while (seconds >= 60 && index < units.length - 1) {
seconds = seconds / 60
index++
}