diff --git a/docs/custom-api.md b/docs/custom-api.md index 566aa58..49502e6 100644 --- a/docs/custom-api.md +++ b/docs/custom-api.md @@ -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: diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go index e9c744f..3d94eb6 100644 --- a/internal/glance/widget-custom-api.go +++ b/internal/glance/widget-custom-api.go @@ -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: