11// SPDX-License-Identifier: AGPL-3.0-only
22// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
33
4+ const SECONDS_PER_MINUTE = 60 ;
5+ const MINUTES_PER_HOUR = 60 ;
6+ const HOURS_PER_DAY = 24 ;
7+ const SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR ;
8+ const MAX_DISPLAYABLE_ETA_SECONDS = HOURS_PER_DAY * SECONDS_PER_HOUR ;
9+
410export function formatBytes ( bytes : number ) : string {
511 if ( ! Number . isFinite ( bytes ) || bytes < 0 ) return "N/A" ;
612 if ( bytes === 0 ) return "0 B" ;
@@ -27,20 +33,16 @@ export function formatRate(bytesPerSec: number): string {
2733export function formatEta ( seconds : number ) : string {
2834 if ( ! Number . isFinite ( seconds ) || seconds <= 0 ) return "" ;
2935 const s = Math . round ( seconds ) ;
30- if ( s < 60 ) return `${ s } s left` ;
31- if ( s < 3600 ) {
32- const m = Math . floor ( s / 60 ) ;
33- const rem = s % 60 ;
36+ if ( s >= MAX_DISPLAYABLE_ETA_SECONDS ) return "" ;
37+ if ( s < SECONDS_PER_MINUTE ) return `${ s } s left` ;
38+ if ( s < SECONDS_PER_HOUR ) {
39+ const m = Math . floor ( s / SECONDS_PER_MINUTE ) ;
40+ const rem = s % SECONDS_PER_MINUTE ;
3441 return rem ? `${ m } m ${ rem } s left` : `${ m } m left` ;
3542 }
36- if ( s < 86400 ) {
37- const h = Math . floor ( s / 3600 ) ;
38- const rem = Math . floor ( ( s % 3600 ) / 60 ) ;
39- return rem ? `${ h } h ${ rem } m left` : `${ h } h left` ;
40- }
41- const d = Math . floor ( s / 86400 ) ;
42- const rem = Math . floor ( ( s % 86400 ) / 3600 ) ;
43- return rem ? `${ d } d ${ rem } h left` : `${ d } d left` ;
43+ const h = Math . floor ( s / SECONDS_PER_HOUR ) ;
44+ const rem = Math . floor ( ( s % SECONDS_PER_HOUR ) / SECONDS_PER_MINUTE ) ;
45+ return rem ? `${ h } h ${ rem } m left` : `${ h } h left` ;
4446}
4547
4648export function ownerOf ( id : string ) : string {
0 commit comments