diff --git a/htmlpage/html.go b/htmlpage/html.go index 7d379c26..8c8a4f56 100644 --- a/htmlpage/html.go +++ b/htmlpage/html.go @@ -118,6 +118,7 @@ func makeFuncMap() template.FuncMap { "timeElapsed": timeElapsed, "timeInterval": timeInterval, "timeSince": timeSince, + "timeSincePtr": timeSincePtr, "uuidShort": uuidShort, } return funcMap @@ -269,12 +270,15 @@ func timeInterval(d time.Duration) string { years := days / 365 return fmt.Sprintf("every %d years", int(math.Round(years))) } -func timeSince(t *time.Time) string { +func timeSincePtr(t *time.Time) string { if t == nil { return "never" } + return timeSince(*t) +} +func timeSince(t time.Time) string { now := time.Now() - diff := now.Sub(*t) + diff := now.Sub(t) hours := diff.Hours() if hours < 1 { diff --git a/sync/template/cell.html b/sync/template/cell.html index 82a9162a..8dd86ca5 100644 --- a/sync/template/cell.html +++ b/sync/template/cell.html @@ -85,8 +85,8 @@
{{.Message}}
- {{.Time | timeSince}} + {{.Time | timeSincePtr}}- Last updated: {{ .LastSync | timeSince }} + Last updated: {{ .LastSync | timeSincePtr }}
{{ end }} @@ -99,7 +99,7 @@ window.addEventListener("load", onLoad);{{ .LastSync | timeSince }}
+{{ .LastSync | timeSincePtr }}
@@ -207,7 +207,7 @@ window.addEventListener("load", onLoad); {{ range $i, $sr := .RecentRequests }}| Creation date | -{{ .Source.Created|timeSince }} | +{{ .Source.Created|timeSincePtr }} | ||
| Edit date | -{{ .Source.EditedAt|timeSince }} | +{{ .Source.EditedAt|timeSincePtr }} | ||
| Larva Inspect Interval | @@ -179,7 +179,7 @@||||
| Last Inspect Date | -{{ .Source.LastInspectionDate|timeSince }} | +{{ .Source.LastInspectionDate|timeSincePtr }} | ||
| Last Inspect Species | @@ -195,7 +195,7 @@||||
| Last Treat Date | -{{ .Source.LastTreatmentDate|timeSince }} | +{{ .Source.LastTreatmentDate|timeSincePtr }} | ||
| Last Treat Product | @@ -211,7 +211,7 @@||||
| Next action date scheduled: | -{{ .Source.NextActionScheduledDate|timeSince }} | +{{ .Source.NextActionScheduledDate|timeSincePtr }} | ||
| Treatment Cadence: | @@ -272,7 +272,7 @@||||
| {{.Date|timeSince}} | +{{.Date|timeSincePtr}} | {{.Product}} | {{.CadenceDelta|timeDelta}} | {{.Notes}} | @@ -304,7 +304,7 @@
| {{.Date|timeSince}} | +{{.Date|timeSincePtr}} | {{.Action}} | {{.Notes}} | |
| {{ .Ended|timeSince }} | +{{ .Ended|timeSincePtr }} | {{ .Females }} | {{ .Males }} | {{ .Total }} | diff --git a/sync/template/trap.html b/sync/template/trap.html index 3f22a94e..cecc11a6 100644 --- a/sync/template/trap.html +++ b/sync/template/trap.html @@ -115,7 +115,7 @@ {{ range .Trap.Collections }}
| {{ .EndDateTime|timeSince }} | +{{ .EndDateTime|timeSincePtr }} | {{ .GlobalID }} | {{ .Count.Females }} | {{ .Count.Males }} |