Skip to content

Commit f066fec

Browse files
committed
add filter duration_seconds'
1 parent 7da1374 commit f066fec

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

assets/templates_src/project/build.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3>{{ part.DockerImage}}. Server version: {{ part.ServerVersion }}</h3>
4343
{{ test.Namespace }}.{{ test.Procedure }}
4444
{% endif %}
4545
</td>
46-
<td>{{ test.FinishedAt | duration:test.StartedAt }}</td>
46+
<td>{{ test.FinishedAt | duration_seconds:test.StartedAt }}</td>
4747
</tr>
4848
{% endfor %}
4949
</tbody>

src/tools/render/filters/time.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
func init() {
1111
pongo2.RegisterFilter("duration", durationFilter)
12+
pongo2.RegisterFilter("duration_seconds", durationSecondsFilter)
1213
pongo2.RegisterFilter("naturaltime", naturaltimeFilter)
1314
}
1415

@@ -27,6 +28,21 @@ func durationFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pong
2728
return pongo2.AsValue(duration(diff)), nil
2829
}
2930

31+
func durationSecondsFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
32+
33+
diff, err := timeDiff(in, param)
34+
35+
if err != nil {
36+
37+
return nil, &pongo2.Error{
38+
Sender: "filter:duration_seconds",
39+
ErrorMsg: err.Error(),
40+
}
41+
}
42+
43+
return pongo2.AsValue(fmt.Sprintf("%.4fs", diff.Seconds())), nil
44+
}
45+
3046
func naturaltimeFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
3147

3248
diff, err := timeDiff(in, param)

0 commit comments

Comments
 (0)