Merge pull request '#122 display dates properly' (#124) from 122-display-time-properly into master
All checks were successful
Build and Push Docker Image / Explore-Gitea-Actions (push) Successful in 57s

Reviewed-on: tim/me-fit#124
This commit was merged in pull request #124.
This commit is contained in:
2024-09-01 21:11:28 +02:00

View File

@@ -1,6 +1,7 @@
package service
import (
"log"
"me-fit/template"
"me-fit/template/workout"
@@ -77,9 +78,8 @@ func HandleNewWorkout(db *sql.DB) http.HandlerFunc {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
wo := workout.Workout{
Date: r.FormValue("date"),
Date: renderDate(date),
Type: r.FormValue("type"),
Sets: r.FormValue("sets"),
Reps: r.FormValue("reps"),
@@ -115,6 +115,12 @@ func HandleGetWorkouts(db *sql.DB) http.HandlerFunc {
return
}
workout.Date, err = renderDateStr(workout.Date)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
workouts = append(workouts, workout)
}
@@ -152,3 +158,17 @@ func HandleDeleteWorkout(db *sql.DB) http.HandlerFunc {
}
}
}
func renderDateStr(date string) (string, error) {
log.Println(date)
t, err := time.Parse("2006-01-02 15:04:05-07:00", date)
if err != nil {
return "", err
}
return renderDate(t), nil
}
func renderDate(date time.Time) string {
return date.Format("2006-01-02")
}