diff --git a/VERSION b/VERSION index 6a36bb4..45263ab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.12 \ No newline at end of file +0.1.13 \ No newline at end of file diff --git a/handlers/plant.go b/handlers/plant.go index fab30b9..4f5abfc 100644 --- a/handlers/plant.go +++ b/handlers/plant.go @@ -1093,7 +1093,12 @@ ORDER BY p.name;` } // Parse the date string into time.Time - plant.HarvestDate, err = time.Parse("2006-01-02", harvestDateStr) + //If harvestDateStr contains T it has a time component, otherwise it's just a date, parse it accordingly + if strings.Contains(harvestDateStr, "T") { + plant.HarvestDate, err = time.Parse("2006-01-02T15:04", harvestDateStr) + } else { + plant.HarvestDate, err = time.Parse("2006-01-02", harvestDateStr) + } if err != nil { fieldLogger.WithError(err).Error("Failed to parse harvest date") return nil, err diff --git a/main.go b/main.go index 5034be7..d8f3d48 100644 --- a/main.go +++ b/main.go @@ -82,9 +82,26 @@ func main() { } return string(a) }, + "formatStringDateTimeLocal": func(t string) string { + parsedTime, err := time.Parse(time.RFC3339, t) + if err != nil { + return "" // Return empty if parsing fails + } + return parsedTime.Format("2006-01-02T15:04") + }, + "formatDateTimeLocal": func(t time.Time) string { + return t.Format("2006-01-02T15:04") + }, + "toLocalTimeString": func(t time.Time) string { + if err != nil { + return "" // Fallback to the original string if parsing fails + } + return t.In(time.Local).Format("01/02/2006 03:04 PM") + }, "formatDate": func(t time.Time) string { return t.Format("01/02/2006") }, + "formatDateTime": func(t time.Time) string { return t.Format("01/02/2006 03:04 PM") }, "formatDateISO": func(t time.Time) string { return t.Format("2006-01-02") }, @@ -126,6 +143,9 @@ func main() { } return t }, + "now": func() time.Time { + return time.Now() + }, } // Attach FuncMap and ParseFS diff --git a/web/templates/components/header2.html b/web/templates/components/header2.html index 2787363..91ae566 100644 --- a/web/templates/components/header2.html +++ b/web/templates/components/header2.html @@ -101,7 +101,7 @@
{{ .Value }} {{ .Unit }}
- {{ formatDate .Date }} + {{ toLocalTimeString .Date }}