diff --git a/src/internal/utils.go b/src/internal/utils.go index 9db5ece..a1aa6fc 100644 --- a/src/internal/utils.go +++ b/src/internal/utils.go @@ -9,6 +9,7 @@ import ( "path/filepath" "regexp" "strings" + "time" ) func ReadConfig(file string, config interface{}) error { @@ -102,6 +103,15 @@ func HumanDuration(i int) string { return fmt.Sprintf("%d %s", i, w) } +// TimeDiff to return the number of seconds between this time and now +func TimeDiff(ts time.Time) int { + diff := int(time.Since(ts).Seconds()) + if diff < 0 { + return diff * -1 + } + return diff +} + func ReturnError(logger *slog.Logger, message string, err error) int { if err != nil { logger.Error(message, slog.Any("error", err)) diff --git a/src/server/server.go b/src/server/server.go index f64e2cc..9284308 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -106,6 +106,7 @@ func (s *Server) Start() error { // Web pages funcs := template.FuncMap{ "HumanDuration": internal.HumanDuration, + "TimeDiff": internal.TimeDiff, "lower": strings.ToLower, "string": func(b []byte) string { return string(b) }, } diff --git a/src/server/templates/note.html b/src/server/templates/note.html index 2570851..09f7b6a 100644 --- a/src/server/templates/note.html +++ b/src/server/templates/note.html @@ -19,13 +19,18 @@