Format execution durations with adaptive units

This commit is contained in:
Lucio Lelii 2026-03-09 17:06:48 +01:00
parent 2446762e88
commit d0ca908b02
3 changed files with 50 additions and 9 deletions

View File

@ -79,12 +79,28 @@ export class TasksExecutor {
}
private formatDuration(startTime: number | null, endTime: number | null): string {
if (!startTime || !endTime) return '00:00:00';
if (!startTime || !endTime) return '0 sec';
const diffMs = Math.max(0, endTime - startTime);
const totalSeconds = Math.floor(diffMs / 1000);
const hh = String(Math.floor(totalSeconds / 3600)).padStart(2, '0');
const mm = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0');
const ss = String(totalSeconds % 60).padStart(2, '0');
return `${hh}:${mm}:${ss}`;
const totalMinutes = Math.floor(totalSeconds / 60);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
if (totalSeconds < 60) {
return `${totalSeconds} sec`;
}
if (totalMinutes < 60) {
const seconds = totalSeconds % 60;
return seconds > 0 ? `${totalMinutes} min ${seconds} sec` : `${totalMinutes} min`;
}
if (totalHours < 24) {
const minutes = totalMinutes % 60;
return minutes > 0 ? `${totalHours} h ${minutes} min` : `${totalHours} h`;
}
const hours = totalHours % 24;
return hours > 0 ? `${totalDays} gg ${hours} h` : `${totalDays} gg`;
}
}

View File

@ -33,7 +33,7 @@
</div>
<div class="bg-slate-50 border border-slate-200 rounded-md p-2">
<div class="text-xs text-slate-500">Duration</div>
<div class="text-sm font-medium text-slate-800">{{ durationMs() != null ? durationMs() + ' ms' : '-' }}</div>
<div class="text-sm font-medium text-slate-800">{{ formattedDuration() }}</div>
</div>
<div class="bg-slate-50 border border-slate-200 rounded-md p-2">
<div class="text-xs text-slate-500">Steps</div>

View File

@ -65,10 +65,10 @@ export class TaskExecutionViewerComponent implements OnDestroy {
return { blocks, connections };
});
readonly durationMs = computed(() => {
readonly formattedDuration = computed(() => {
const context = this.execution()?.context;
if (!context?.startTime || !context?.endTime) return null;
return Math.max(0, context.endTime - context.startTime);
if (!context?.startTime || !context?.endTime) return '-';
return this.formatDuration(context.startTime, context.endTime);
});
readonly inputsReadOnly = computed(() => {
@ -239,6 +239,31 @@ export class TaskExecutionViewerComponent implements OnDestroy {
this.textInputDebounceTimers.delete(timerKey);
}
private formatDuration(startTime: number, endTime: number): string {
const diffMs = Math.max(0, endTime - startTime);
const totalSeconds = Math.floor(diffMs / 1000);
const totalMinutes = Math.floor(totalSeconds / 60);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
if (totalSeconds < 60) {
return `${totalSeconds} sec`;
}
if (totalMinutes < 60) {
const seconds = totalSeconds % 60;
return seconds > 0 ? `${totalMinutes} min ${seconds} sec` : `${totalMinutes} min`;
}
if (totalHours < 24) {
const minutes = totalMinutes % 60;
return minutes > 0 ? `${totalHours} h ${minutes} min` : `${totalHours} h`;
}
const hours = totalHours % 24;
return hours > 0 ? `${totalDays} gg ${hours} h` : `${totalDays} gg`;
}
private inferConnections(steps: TaskExecutionStep[]) {
const connections: FlowData['connections'] = [];