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 @@
{{ .lcl.plant_details }}
{{ end }}
  • {{ .lcl.title_zone }}: {{ .plant.ZoneName }}
  • -
  • {{ .lcl.start_date }}: {{ formatDate .plant.StartDT }}
  • +
  • {{ .lcl.start_date }}: {{ formatDateTime .plant.StartDT }}
  • {{ if and (eq .plant.Autoflower true) (ne .plant.Status "Success") (ne .plant.Status "Drying") (ne .plant.Status "Curing") (ne .plant.Status "Dead") }} @@ -125,7 +125,7 @@
    {{ .lcl.plant_details }}
    {{ if or (eq .plant.Status "Success") (eq .plant.Status "Drying") (eq .plant.Status "Curing") (eq .plant.Status "Dead") }} -
  • {{ .lcl.harvest_date }}: {{ formatDate .plant.HarvestDate }}
  • +
  • {{ .lcl.harvest_date }}: {{ formatDateTime .plant.HarvestDate }}
  • {{ .lcl.harvest_weight }}: {{ .plant.HarvestWeight }} {{ .lcl.title_grams }}
  • {{ else }}
  • {{ .lcl.title_day }}: {{ .plant.CurrentDay }}
  • @@ -138,12 +138,12 @@
    {{ .lcl.plant_details }}
    {{ end }} - {{ if or (ne (formatDate .plant.LastWaterDate) "01/01/1970") (ne (formatDate .plant.LastFeedDate) "01/01/1970") }} + {{ if or (ne (formatDateTime .plant.LastWaterDate) "01/01/1970") (ne (formatDateTime .plant.LastFeedDate) "01/01/1970") }}
  • {{ .lcl.last_watered_or_fed }}: - {{ if gt (formatDate .plant.LastWaterDate) (formatDate .plant.LastFeedDate) }} - {{ formatDate .plant.LastWaterDate }} ({{ .lcl.title_watered }}) + {{ if gt (formatDateTime .plant.LastWaterDate) (formatDateTime .plant.LastFeedDate) }} + {{ formatDateTime .plant.LastWaterDate }} ({{ .lcl.title_watered }}) {{ else }} - {{ formatDate .plant.LastFeedDate }} ({{ .lcl.title_fed }}) + {{ formatDateTime .plant.LastFeedDate }} ({{ .lcl.title_fed }}) {{ end }}
  • {{ end }} @@ -219,7 +219,7 @@

    {{ .lcl.title_sensors }}

    {{ .Name }}

    {{ .Value }} {{ .Unit }}

    - {{ formatDate .Date }} + {{ toLocalTimeString .Date }}
    @@ -243,7 +243,7 @@

    {{ .lcl.status_history }}

    {{ range .plant.StatusHistory }} - {{ formatDate .Date }} + {{ formatDateTime .Date }} {{ .Status }} {{ end }} @@ -267,7 +267,7 @@

    {{ .lcl.title_measurements }}

    {{ range .plant.Measurements }} - {{ formatDate .Date }} + {{ formatDateTime .Date }} {{ .Name }} {{ .Value }} @@ -292,7 +292,7 @@

    {{ .lcl.title_activities }}

    {{ range .plant.Activities }} - {{ formatDate .Date }} + {{ formatDateTime .Date }} {{ .Name }} {{ preview .Note }} @@ -528,7 +528,7 @@
    - +
    @@ -540,7 +540,7 @@
    - +
    @@ -658,7 +658,7 @@
    - +
    @@ -721,7 +721,7 @@
    - +
    {{ if .loggedIn }} @@ -746,7 +746,7 @@