Skip to content

Commit c67eb4d

Browse files
committed
Add startOfDay and endOfDay funcs
1 parent e99ee4f commit c67eb4d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

docs/custom-api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ The following helper functions provided by Glance are available:
447447
- `concat(strings ...string) string`: Concatenates multiple strings together.
448448
- `unique(key string, arr []JSON) []JSON`: Returns a unique array of JSON objects based on the given key.
449449
- `percentChange(current float, previous float) float`: Calculates the percentage change between two numbers.
450+
- `startOfDay(t time.Time) time.Time`: Returns the start of the day for a given time.
451+
- `endOfDay(t time.Time) time.Time`: Returns the end of the day for a given time.
450452

451453
The following helper functions provided by Go's `text/template` are available:
452454

internal/glance/widget-custom-api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ var customAPITemplateFuncs = func() template.FuncMap {
509509
// Shorthand to do both of the above with a single function call
510510
return dynamicRelativeTimeAttrs(customAPIFuncParseTimeInLocation(layout, value, time.UTC))
511511
},
512+
"startOfDay": func(t time.Time) time.Time {
513+
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
514+
},
515+
"endOfDay": func(t time.Time) time.Time {
516+
return time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location())
517+
},
512518
// The reason we flip the parameter order is so that you can chain multiple calls together like this:
513519
// {{ .JSON.String "foo" | trimPrefix "bar" | doSomethingElse }}
514520
// instead of doing this:

0 commit comments

Comments
 (0)