Add startOfDay and endOfDay funcs

This commit is contained in:
Svilen Markov
2025-05-14 22:05:35 +01:00
parent e99ee4f774
commit c67eb4d2c0
2 changed files with 8 additions and 0 deletions

View File

@@ -509,6 +509,12 @@ var customAPITemplateFuncs = func() template.FuncMap {
// Shorthand to do both of the above with a single function call
return dynamicRelativeTimeAttrs(customAPIFuncParseTimeInLocation(layout, value, time.UTC))
},
"startOfDay": func(t time.Time) time.Time {
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
},
"endOfDay": func(t time.Time) time.Time {
return time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location())
},
// The reason we flip the parameter order is so that you can chain multiple calls together like this:
// {{ .JSON.String "foo" | trimPrefix "bar" | doSomethingElse }}
// instead of doing this: