diff options
author | 2023-10-17 17:56:17 -0700 | |
---|---|---|
committer | 2023-10-17 21:25:41 -0700 | |
commit | 23d2cfe0f98f3d6acc04ef11653d3dbaf0b0b677 (patch) | |
tree | 0ad635863d1bf49b38bbb7013babd61dd27d9660 /internal/template/functions.go | |
parent | 5dc44453bad925750cf2dda1172df785f740c935 (diff) | |
download | v2-23d2cfe0f98f3d6acc04ef11653d3dbaf0b0b677.tar.gz v2-23d2cfe0f98f3d6acc04ef11653d3dbaf0b0b677.tar.zst v2-23d2cfe0f98f3d6acc04ef11653d3dbaf0b0b677.zip |
Expose `next_check_at` in the web ui and API
Diffstat (limited to 'internal/template/functions.go')
-rw-r--r-- | internal/template/functions.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/template/functions.go b/internal/template/functions.go index 97ca0f3d..f617029c 100644 --- a/internal/template/functions.go +++ b/internal/template/functions.go @@ -107,7 +107,8 @@ func (f *funcMap) Map() template.FuncMap { "nonce": func() string { return crypto.GenerateRandomStringHex(16) }, - "deRef": func(i *int) int { return *i }, + "deRef": func(i *int) int { return *i }, + "duration": duration, // These functions are overrode at runtime after the parsing. "elapsed": func(timezone string, t time.Time) string { @@ -160,6 +161,21 @@ func isEmail(str string) bool { return err == nil } +// Returns the duration in human readable format (hours and minutes). +func duration(t time.Time) string { + if t.IsZero() { + return "" + } + + diff := time.Until(t) + + if diff < 0 { + return "" + } + + return diff.String() +} + func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { if t.IsZero() { return printer.Printf("time_elapsed.not_yet") |