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 @@ {{.ID|uuidShort}} {{.Type}} - {{.LastInspected|timeSince}} - {{.LastTreated|timeSince}} + {{.LastInspected|timeSincePtr}} + {{.LastTreated|timeSincePtr}} {{ end }} @@ -130,7 +130,7 @@ {{.LocationID|uuidShort}} {{.Location}} - {{.Date|timeSince}} + {{.Date|timeSincePtr}} {{.Action}} {{.Notes}} @@ -208,7 +208,7 @@ {{ range .Treatments }} {{.LocationID|uuidShort}} - {{.Date|timeSince}} + {{.Date|timeSincePtr}} {{.Product}} {{.Notes}} diff --git a/sync/template/components/header.html b/sync/template/components/header.html index 00f43dad..20967b2b 100644 --- a/sync/template/components/header.html +++ b/sync/template/components/header.html @@ -46,7 +46,7 @@

{{.Message}}

- {{.Time | timeSince}} + {{.Time | timeSincePtr}}
diff --git a/sync/template/dashboard.html b/sync/template/dashboard.html index 370ae135..f7880123 100644 --- a/sync/template/dashboard.html +++ b/sync/template/dashboard.html @@ -82,7 +82,7 @@ window.addEventListener("load", onLoad);

{{ else }}

- Last updated: {{ .LastSync | timeSince }} + Last updated: {{ .LastSync | timeSincePtr }}

{{ end }} @@ -99,7 +99,7 @@ window.addEventListener("load", onLoad);
Last Data Refresh
-

{{ .LastSync | timeSince }}

+

{{ .LastSync | timeSincePtr }}

@@ -207,7 +207,7 @@ window.addEventListener("load", onLoad); {{ range $i, $sr := .RecentRequests }} - {{ $sr.Date | timeSince }} + {{ $sr.Date | timeSincePtr }} Service Request {{ $sr.Location }} Completed diff --git a/sync/template/source.html b/sync/template/source.html index 2b66a6fb..15d7976e 100644 --- a/sync/template/source.html +++ b/sync/template/source.html @@ -147,11 +147,11 @@ - + - + @@ -179,7 +179,7 @@ - + @@ -195,7 +195,7 @@ - + @@ -211,7 +211,7 @@ - + @@ -272,7 +272,7 @@ {{ range .Treatments }} - + @@ -304,7 +304,7 @@ {{ range .Inspections }} - + @@ -348,7 +348,7 @@ {{ range .Counts }} - + 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 }} - +
Creation date{{ .Source.Created|timeSince }}{{ .Source.Created|timeSincePtr }}
Edit date{{ .Source.EditedAt|timeSince }}{{ .Source.EditedAt|timeSincePtr }}
Larva Inspect Interval
Last Inspect Date{{ .Source.LastInspectionDate|timeSince }}{{ .Source.LastInspectionDate|timeSincePtr }}
Last Inspect Species
Last Treat Date{{ .Source.LastTreatmentDate|timeSince }}{{ .Source.LastTreatmentDate|timeSincePtr }}
Last Treat Product
Next action date scheduled:{{ .Source.NextActionScheduledDate|timeSince }}{{ .Source.NextActionScheduledDate|timeSincePtr }}
Treatment Cadence:
{{.Date|timeSince}}{{.Date|timeSincePtr}} {{.Product}} {{.CadenceDelta|timeDelta}} {{.Notes}}
{{.Date|timeSince}}{{.Date|timeSincePtr}} {{.Action}} {{.Notes}}
{{ .Ended|timeSince }}{{ .Ended|timeSincePtr }} {{ .Females }} {{ .Males }} {{ .Total }}
{{ .EndDateTime|timeSince }}{{ .EndDateTime|timeSincePtr }} {{ .GlobalID }} {{ .Count.Females }} {{ .Count.Males }}