diff --git a/main.go b/main.go index 0f215b9..cd97d07 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ func main() { "truncate": truncateText, "categoryIcon": categoryIcon, "formatDate": formatDate, + "formatDateTime": formatDateTime, "lower": strings.ToLower, "title": strings.Title, "safe": func(s string) template.HTML { return template.HTML(s) }, @@ -164,6 +165,28 @@ func formatDate(s string) string { return s } +func formatDateTime(s string) string { + formats := []string{ + "2006-01-02T15:04:05-07:00", + "2006-01-02T15:04:05.999999-07:00", + "2006-01-02T15:04:05.999999", + "2006-01-02T15:04:05", + "2006-01-02 15:04:05", + "2006-01-02", + } + loc, _ := time.LoadLocation("America/New_York") + if loc == nil { + loc = time.UTC + } + for _, f := range formats { + if t, err := time.Parse(f, s); err == nil { + t = t.In(loc) + return t.Format("01/02/2006 3:04 PM EST") + } + } + return s +} + // Template rendering func renderTemplate(w http.ResponseWriter, name string, data interface{}) { diff --git a/templates/dashboard.html b/templates/dashboard.html index 0e3408c..b44e0e2 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -120,23 +120,17 @@ {{if .Stats.RecentUploads}}
{{formatDate .ProcessedAt}}
+{{formatDateTime .ProcessedAt}}