diff options
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") |