Skip to content

Commit 0d82e90

Browse files
authored
fix(orchestrator): resolve inconsistency with workflow run average duration format (#1191)
fix(orchestrator): resolve inconsistency with workflow run average duration format
1 parent afebb56 commit 0d82e90

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

plugins/orchestrator/src/dataFormatters/WorkflowOverviewFormatter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('WorkflowOverviewAdapter', () => {
2828
);
2929
expect(adaptedData.lastRunStatus).toBe(mockWorkflowOverview.lastRunStatus);
3030
expect(adaptedData.category).toBe(mockWorkflowOverview.category);
31-
expect(adaptedData.avgDuration).toBe('2 min');
31+
expect(adaptedData.avgDuration).toBe('3 minutes');
3232
expect(adaptedData.description).toBe(mockWorkflowOverview.description);
3333
expect(adaptedData.format).toBe('yaml'); // Adjust based on your expected value
3434
});

plugins/orchestrator/src/dataFormatters/WorkflowOverviewFormatter.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,8 @@ export interface FormattedWorkflowOverview {
2020
readonly format: WorkflowFormat;
2121
}
2222

23-
const formatDuration = (milliseconds: number): string => {
24-
let sec = Math.round(milliseconds / 1000);
25-
let min = 0;
26-
let hr = 0;
27-
if (sec >= 60) {
28-
min = Math.floor(sec / 60);
29-
sec %= 60;
30-
}
31-
if (min >= 60) {
32-
hr = Math.floor(min / 60);
33-
min %= 60;
34-
}
35-
if (hr > 0) {
36-
return `${hr} h`;
37-
}
38-
if (min > 0) {
39-
return `${min} min`;
40-
}
41-
if (sec > 0) {
42-
return `${sec} sec`;
43-
}
44-
return 'less than a sec';
45-
};
23+
const formatDuration = (milliseconds: number): string =>
24+
moment.duration(milliseconds).humanize();
4625

4726
const WorkflowOverviewFormatter: DataFormatter<
4827
WorkflowOverview,

0 commit comments

Comments
 (0)