diff --git a/html/func.go b/html/func.go index 98919e21..4b687258 100644 --- a/html/func.go +++ b/html/func.go @@ -30,8 +30,8 @@ func addFuncMap(t *template.Template) { "timeDelta": timeDelta, "timeElapsed": timeElapsed, "timeInterval": timeInterval, - "timeSince": timeSince, - "timeSincePtr": timeSincePtr, + "timeRelative": timeRelative, + "timeRelativePtr": timeRelativePtr, "uuidShort": uuidShort, } t.Funcs(funcMap) @@ -179,27 +179,43 @@ func timeInterval(d time.Duration) string { years := days / 365 return fmt.Sprintf("every %d years", int(math.Round(years))) } -func timeSincePtr(t *time.Time) string { - if t == nil { - return "never" - } - return timeSince(*t) -} -func timeSince(t time.Time) string { +func timeRelative(t time.Time) string { now := time.Now() diff := now.Sub(t) hours := diff.Hours() - if hours < 1 { - minutes := diff.Minutes() - return fmt.Sprintf("%d minutes ago", int(minutes)) - } else if hours < 24 { - return fmt.Sprintf("%d hours ago", int(hours)) + if hours > 0 { + if hours < 1 { + minutes := diff.Minutes() + return fmt.Sprintf("%d minutes ago", int(minutes)) + } else if hours < 24 { + return fmt.Sprintf("%d hours ago", int(hours)) + } else { + days := hours / 24 + return fmt.Sprintf("%d days ago", int(days)) + } } else { - days := hours / 24 - return fmt.Sprintf("%d days ago", int(days)) + if hours < -24 { + days := hours / 24 + return fmt.Sprintf("in %d days", -1*int(days)) + } else if hours < -1 { + return fmt.Sprintf("in %d hours", -1*int(hours)) + } else { + minutes := diff.Minutes() + if minutes > -1 { + seconds := diff.Seconds() + return fmt.Sprintf("in %d seconds", -1*int(seconds)) + } + return fmt.Sprintf("in %d minutes", -1*int(minutes)) + } } } +func timeRelativePtr(t *time.Time) string { + if t == nil { + return "never" + } + return timeRelative(*t) +} func unescapeHTML(s string) template.HTML { return template.HTML(s) } diff --git a/html/template/rmo/status-by-id.html b/html/template/rmo/status-by-id.html index bc2c6f8c..ffa578ab 100644 --- a/html/template/rmo/status-by-id.html +++ b/html/template/rmo/status-by-id.html @@ -80,7 +80,7 @@ document.addEventListener("DOMContentLoaded", onLoad);
Created: - {{ .Report.Created|timeSince }} + {{ .Report.Created|timeRelative }}
District: @@ -148,7 +148,7 @@ document.addEventListener("DOMContentLoaded", onLoad);
{{ range .Timeline }}
-
{{ .At|timeSince }}
+
{{ .At|timeRelative }}
{{ .Title }}

{{ .Detail }}

diff --git a/html/template/sync/cell.html b/html/template/sync/cell.html index 0bd7d065..a450448f 100644 --- a/html/template/sync/cell.html +++ b/html/template/sync/cell.html @@ -89,8 +89,8 @@ {{ .ID|uuidShort }} {{ .Type }} - {{ .LastInspected|timeSincePtr }} - {{ .LastTreated|timeSincePtr }} + {{ .LastInspected|timeRelativePtr }} + {{ .LastTreated|timeRelativePtr }} {{ end }} @@ -138,7 +138,7 @@ > {{ .Location }} - {{ .Date|timeSincePtr }} + {{ .Date|timeRelativePtr }} {{ .Action }} {{ .Notes }} @@ -225,7 +225,7 @@ >{{ .LocationID|uuidShort }} - {{ .Date|timeSincePtr }} + {{ .Date|timeRelativePtr }} {{ .Product }} {{ .Notes }} diff --git a/html/template/sync/component/header.html b/html/template/sync/component/header.html index 0a520e12..06a6d70d 100644 --- a/html/template/sync/component/header.html +++ b/html/template/sync/component/header.html @@ -87,7 +87,7 @@

{{ .Message }}

{{ .Time | timeSincePtr }}{{ .Time | timeRelativePtr }}
diff --git a/html/template/sync/dashboard.html b/html/template/sync/dashboard.html index 820ee706..c6d1fc0f 100644 --- a/html/template/sync/dashboard.html +++ b/html/template/sync/dashboard.html @@ -37,7 +37,9 @@ {{ else }}

Last updated: - {{ .LastSync | timeSincePtr }} + {{ .LastSync | timeRelativePtr }} @@ -56,7 +58,7 @@

Last Data Refresh
-

{{ .LastSync | timeSincePtr }}

+

{{ .LastSync | timeRelativePtr }}

@@ -172,7 +174,7 @@ {{ range $i, $sr := .RecentRequests }} - {{ $sr.Date | timeSincePtr }} + {{ $sr.Date | timeRelativePtr }} Service Request {{ $sr.Location }} Completed diff --git a/html/template/sync/notification-list.html b/html/template/sync/notification-list.html index c4f9a490..b564b872 100644 --- a/html/template/sync/notification-list.html +++ b/html/template/sync/notification-list.html @@ -50,7 +50,9 @@
{{ .Message }}
-
{{ .Time|timeSince }}
+
+ {{ .Time|timeRelative }} +
diff --git a/html/template/sync/pool-list.html b/html/template/sync/pool-list.html index 3306bfa3..01e7a941 100644 --- a/html/template/sync/pool-list.html +++ b/html/template/sync/pool-list.html @@ -39,7 +39,7 @@ {{ range .Uploads }} {{ .Status }} - {{ .Created|timeSince }} + {{ .Created|timeRelative }} {{ end }} diff --git a/html/template/sync/setting-integration.html b/html/template/sync/setting-integration.html index d879a122..598f78f2 100644 --- a/html/template/sync/setting-integration.html +++ b/html/template/sync/setting-integration.html @@ -86,7 +86,7 @@ Token Expiration - {{ .ArcGISOAuth.AccessTokenExpires|timeSince }} + {{ .ArcGISOAuth.AccessTokenExpires|timeRelative }} Integration Method diff --git a/html/template/sync/source.html b/html/template/sync/source.html index b3a9524d..a7f9b947 100644 --- a/html/template/sync/source.html +++ b/html/template/sync/source.html @@ -149,11 +149,11 @@ - + - + @@ -181,7 +181,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -213,7 +213,7 @@ - + @@ -274,7 +274,7 @@ {{ range .Treatments }} - + {{ range .Inspections }} - + @@ -351,7 +351,7 @@ {{ range .Counts }} - + diff --git a/html/template/sync/trap.html b/html/template/sync/trap.html index 2207fec3..c00af6e9 100644 --- a/html/template/sync/trap.html +++ b/html/template/sync/trap.html @@ -115,7 +115,7 @@ {{ range .Trap.Collections }} - +
Creation date{{ .Source.Created|timeSincePtr }}{{ .Source.Created|timeRelativePtr }}
Edit date{{ .Source.EditedAt|timeSincePtr }}{{ .Source.EditedAt|timeRelativePtr }}
Larva Inspect Interval
Last Inspect Date{{ .Source.LastInspectionDate|timeSincePtr }}{{ .Source.LastInspectionDate|timeRelativePtr }}
Last Inspect Species
Last Treat Date{{ .Source.LastTreatmentDate|timeSincePtr }}{{ .Source.LastTreatmentDate|timeRelativePtr }}
Last Treat Product
Next action date scheduled:{{ .Source.NextActionScheduledDate|timeSincePtr }}{{ .Source.NextActionScheduledDate|timeRelativePtr }}
Treatment Cadence:
{{ .Date|timeSincePtr }}{{ .Date|timeRelativePtr }} {{ .Product }} {{ .CadenceDelta|timeDelta }} @@ -307,7 +307,7 @@
{{ .Date|timeSincePtr }}{{ .Date|timeRelativePtr }} {{ .Action }} {{ .Notes }}
{{ .Ended|timeSincePtr }}{{ .Ended|timeRelativePtr }} {{ .Females }} {{ .Males }} {{ .Total }}
{{ .EndDateTime|timeSincePtr }}{{ .EndDateTime|timeRelativePtr }} {{ .GlobalID }} {{ .Count.Females }} {{ .Count.Males }}