mirror of
https://github.com/langgenius/dify.git
synced 2026-06-26 06:41:10 +08:00
Merge a7e07e008d into a246dc8b17
This commit is contained in:
commit
00e96d6444
@ -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', () => {
|
||||
|
||||
@ -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++
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user