From b6b71c592184fea460566c9508668baad4c59848 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Wed, 1 Apr 2020 00:10:55 -0600 Subject: [PATCH] Give dateFmt consants better names --- http/server.go | 10 +++++----- store.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/http/server.go b/http/server.go index 0b04c4d..404ca88 100644 --- a/http/server.go +++ b/http/server.go @@ -87,12 +87,12 @@ func (h *handler) handleCreate(w http.ResponseWriter, r *http.Request) { } func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) { - earliest, err := time.Parse(dateFmt, r.FormValue(fieldNameEarliest)) + earliest, err := time.Parse(formDateLayout, r.FormValue(fieldNameEarliest)) if err != nil { fmt.Fprint(w, "bad earliest date") return } - latest, err := time.Parse(dateFmt, r.FormValue(fieldNameLatest)) + latest, err := time.Parse(formDateLayout, r.FormValue(fieldNameLatest)) if err != nil { fmt.Fprint(w, "bad latest date") return @@ -173,7 +173,7 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) { e.Input( a.Name(fieldNameEarliest), a.Type("date"), - a.Value(event.EarliestDate.Format(dateFmt)), + a.Value(event.EarliestDate.Format(formDateLayout)), ), e.Br(), @@ -181,7 +181,7 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) { e.Input( a.Name(fieldNameLatest), a.Type("date"), - a.Value(event.LatestDate.Format(dateFmt)), + a.Value(event.LatestDate.Format(formDateLayout)), ), e.Br(), @@ -240,7 +240,7 @@ func genString() (string, error) { return buf.String(), nil } -const dateFmt = "2006-01-02" +const formDateLayout = "2006-01-02" func main() { addr := flag.String("address", ":8080", "bind address for HTTP server as host:port") diff --git a/store.go b/store.go index 79e902b..a04ebe8 100644 --- a/store.go +++ b/store.go @@ -99,7 +99,7 @@ type CreateEventResult struct { AlphaID, AdminCode string } -const dateFmt = "2006-01-02" +const dbDateLayout = "2006-01-02" func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result CreateEventResult, err error) { conn := s.pool.Get(ctx) @@ -123,8 +123,8 @@ func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result adminCode, cmd.Name, cmd.Description, - cmd.EarliestDate.Format(dateFmt), - cmd.LatestDate.Format(dateFmt), + cmd.EarliestDate.Format(dbDateLayout), + cmd.LatestDate.Format(dbDateLayout), ) if err != nil { return @@ -165,11 +165,11 @@ func (s *Store) GetEvent(ctx context.Context, query GetEventQuery) (GetEventResu latestDateString := stmt.ColumnText(3) var err error - result.EarliestDate, err = time.Parse(dateFmt, earliestDateString) + result.EarliestDate, err = time.Parse(dbDateLayout, earliestDateString) if err != nil { return err } - result.LatestDate, err = time.Parse(dateFmt, latestDateString) + result.LatestDate, err = time.Parse(dbDateLayout, latestDateString) return err }, query.AlphaID) if err != nil {