mirror of
https://github.com/glanceapp/glance.git
synced 2025-08-15 10:49:03 +02:00
Add startOfDay and endOfDay funcs
This commit is contained in:
@ -447,6 +447,8 @@ The following helper functions provided by Glance are available:
|
||||
- `concat(strings ...string) string`: Concatenates multiple strings together.
|
||||
- `unique(key string, arr []JSON) []JSON`: Returns a unique array of JSON objects based on the given key.
|
||||
- `percentChange(current float, previous float) float`: Calculates the percentage change between two numbers.
|
||||
- `startOfDay(t time.Time) time.Time`: Returns the start of the day for a given time.
|
||||
- `endOfDay(t time.Time) time.Time`: Returns the end of the day for a given time.
|
||||
|
||||
The following helper functions provided by Go's `text/template` are available:
|
||||
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user