Skip to content

A self-hosted dashboard that puts all your feeds in one place

Add offsetNow function

Svilen Markov964744a9ae6d
diff --git a/docs/custom-api.md b/docs/custom-api.md
index 42467da..336c861 100644
--- a/docs/custom-api.md
+++ b/docs/custom-api.md
@@ -375,6 +375,7 @@ The following helper functions provided by Glance are available:
- `toInt(f float) int`: Converts a float to an integer.
- `toRelativeTime(t time.Time) template.HTMLAttr`: Converts Time to a relative time such as 2h, 1d, etc which dynamically updates. **NOTE:** the value of this function should be used as an attribute in an HTML tag, e.g. `<span {{ toRelativeTime .Time }}></span>`.
- `now() time.Time`: Returns the current time.
+- `offsetNow(offset string) time.Time`: Returns the current time with an offset. The offset can be positive or negative and must be in the format "3h" "-1h" or "2h30m10s".
- `duration(str string) time.Duration`: Parses a string such as `1h`, `1d`, `5h30m`, etc into a `time.Duration`.
- `parseTime(layout string, s string) time.Time`: Parses a string into time.Time. The layout must be provided in Go's [date format](https://pkg.go.dev/time#pkg-constants). You can alternatively use these values instead of the literal format: "unix", "RFC3339", "RFC3339Nano", "DateTime", "DateOnly".
- `parseRelativeTime(layout string, s string) time.Time`: A shorthand for `{{ .String "date" | parseTime "rfc3339" | toRelativeTime }}`.
diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go
index e8ac225..c9db2df 100644
--- a/internal/glance/widget-custom-api.go
+++ b/internal/glance/widget-custom-api.go
@@ -435,6 +435,13 @@ var customAPITemplateFuncs = func() template.FuncMap {
"now": func() time.Time {
return time.Now()
},
+ "offsetNow": func(offset string) time.Time {
+ d, err := time.ParseDuration(offset)
+ if err != nil {
+ return time.Now()
+ }
+ return time.Now().Add(d)
+ },
"duration": func(str string) time.Duration {
d, err := time.ParseDuration(str)
if err != nil {