Smooth download speed and time remaining
This commit is contained in:
1 parent
68c7dd76f2
commit
596caf57ee
4 files changed
+65
-36
No files matched your search
+18
-8
@@ -22,14 +22,24 @@ export function formatBytes(bytes) {
|
||||
return `${value.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
export function formatDuration(seconds) {
|
||||
const total = Math.max(0, Math.round(seconds));
|
||||
const hours = Math.floor(total / 3600);
|
||||
const minutes = Math.floor((total % 3600) / 60);
|
||||
const remainingSeconds = total % 60;
|
||||
if (hours > 0) return `${hours}h ${minutes}m`;
|
||||
if (minutes > 0) return `${minutes}m ${remainingSeconds}s`;
|
||||
return `${remainingSeconds}s`;
|
||||
function roundTo(value, step) {
|
||||
return Math.max(step, Math.round(value / step) * step);
|
||||
}
|
||||
|
||||
export function formatRemaining(seconds) {
|
||||
if (!Number.isFinite(seconds) || seconds <= 0) return "almost done";
|
||||
if (seconds < 60) return `${roundTo(seconds, 5)}s`;
|
||||
if (seconds < 600) {
|
||||
const rounded = roundTo(seconds, 15);
|
||||
const minutes = Math.floor(rounded / 60);
|
||||
const remainingSeconds = rounded % 60;
|
||||
return remainingSeconds === 0 ? `${minutes}m` : `${minutes}m ${remainingSeconds}s`;
|
||||
}
|
||||
if (seconds < 3600) return `${roundTo(seconds / 60, 1)}m`;
|
||||
const totalMinutes = roundTo(seconds / 60, 5);
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
return minutes === 0 ? `${hours}h` : `${hours}h ${minutes}m`;
|
||||
}
|
||||
|
||||
export function formatDate(value) {
|
||||
|
||||
Reference in new issue
Block a user