Skip to content

Commit 1192843

Browse files
authored
docs: show conversion from duration to seconds (#44)
## Description <!-- Please provide a clear and concise description of what the pull request achieves. Mention the issue it addresses (if applicable). --> I use Go templates to produce machine-readable files, and one of the challenges I face is producing amounts of time as seconds and milliseconds. I want to write values like "5 minutes" or "30 seconds" for the benefit of file maintainers and have a computer do the math to turn them into numbers. The `toDuration` function satisfies my use case and seems valuable to show in the documentation. ## Changes <!-- - Detail the changes you have introduced. - Highlight any new functionality. --> One more example for the `toDuration` function. ## Fixes <!-- #issueNumber --> ## Checklist - [x] I have read the **CONTRIBUTING.md** document. - [x] My code follows the code style of this project. - [x] I have added tests to cover my changes. - [x] All new and existing tests passed. - [x] I have updated the documentation accordingly. - [x] This change requires a change to the documentation on the website. ## Additional Information <!-- Any additional information regarding this pull request. --> This example matches this test: https://github.com/go-sprout/sprout/blob/aca5c32cd0f8340e64998aa718dee2b3564717d4/conversion_functions_test.go#L130
1 parent aca5c32 commit 1192843

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

docs/functions/type-conversions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m` and `h`.
205205
{{ (1000.0 * 1000.0) | toDuration }} // Output: 1ms
206206
{{ "1m" | toDuration }} // Output: 1m
207207
{{ "invalid" | toDuration }} // Output: 0s
208+
{{ (toDuration "1h30m").Seconds }} // Output: 5400
208209
```
209210
{% endtab %}
210211
{% endtabs %}

0 commit comments

Comments
 (0)