Skip to content

Commit 5e898b3

Browse files
committed
fix: format duration in backend
1 parent 2e8aff7 commit 5e898b3

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

routers/web/repo/actions/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ type ViewJob struct {
7979
}
8080

8181
type ViewJobStep struct {
82-
Summary string `json:"summary"`
83-
Duration float64 `json:"duration"`
84-
Status string `json:"status"`
82+
Summary string `json:"summary"`
83+
Duration string `json:"duration"`
84+
Status string `json:"status"`
8585
}
8686

8787
type ViewStepLog struct {
@@ -154,7 +154,7 @@ func ViewPost(ctx *context_module.Context) {
154154
for i, v := range steps {
155155
resp.StateData.CurrentJobSteps[i] = ViewJobStep{
156156
Summary: v.Name,
157-
Duration: float64(v.Duration() / time.Second),
157+
Duration: v.Duration().Round(time.Second).String(),
158158
Status: v.Status.String(),
159159
}
160160
}

web_src/js/components/RepoActionView.vue

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<SvgIcon name="octicon-x-circle-fill" class="red mr-3 " v-else/>
5252

5353
<span class="step-summary-msg">{{ jobStep.summary }}</span>
54-
<span class="step-summary-dur">{{ formatDuration(jobStep.duration) }}</span>
54+
<span class="step-summary-dur">{{ jobStep.duration }}</span>
5555
</div>
5656

5757
<!-- the log elements could be a lot, do not use v-if to destroy/reconstruct the DOM -->
@@ -162,27 +162,6 @@ const sfc = {
162162
});
163163
},
164164
165-
formatDuration(d) {
166-
d = Math.round(d);
167-
const unitValues = [60, 60, 24];
168-
const unitNames = ['s', 'm', 'h', 'd'];
169-
const parts = [];
170-
for (let i = 0; i < unitValues.length; i++) {
171-
parts[i] = d % unitValues[i];
172-
d = Math.floor(d / unitValues[i]);
173-
}
174-
parts.push(d);
175-
let res = '', resCount = 0;
176-
for (let i = parts.length - 1; i >= 0 && resCount < 2; i--) {
177-
if (parts[i] > 0) {
178-
res += `${parts[i] + unitNames[i]} `;
179-
resCount++;
180-
}
181-
}
182-
if (!res) return '0s';
183-
return res.substring(0, res.length - 1);
184-
},
185-
186165
createLogLine(line) {
187166
const div = document.createElement('div');
188167
div.classList.add('job-log-line');

0 commit comments

Comments
 (0)