Give dateFmt consants better names

This commit is contained in:
Brandon Dyck 2020-04-01 00:10:55 -06:00
parent 3504ecd196
commit b6b71c5921
2 changed files with 10 additions and 10 deletions

View File

@ -87,12 +87,12 @@ func (h *handler) handleCreate(w http.ResponseWriter, r *http.Request) {
} }
func (h *handler) handleDoCreate(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 { if err != nil {
fmt.Fprint(w, "bad earliest date") fmt.Fprint(w, "bad earliest date")
return return
} }
latest, err := time.Parse(dateFmt, r.FormValue(fieldNameLatest)) latest, err := time.Parse(formDateLayout, r.FormValue(fieldNameLatest))
if err != nil { if err != nil {
fmt.Fprint(w, "bad latest date") fmt.Fprint(w, "bad latest date")
return return
@ -173,7 +173,7 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
e.Input( e.Input(
a.Name(fieldNameEarliest), a.Name(fieldNameEarliest),
a.Type("date"), a.Type("date"),
a.Value(event.EarliestDate.Format(dateFmt)), a.Value(event.EarliestDate.Format(formDateLayout)),
), ),
e.Br(), e.Br(),
@ -181,7 +181,7 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
e.Input( e.Input(
a.Name(fieldNameLatest), a.Name(fieldNameLatest),
a.Type("date"), a.Type("date"),
a.Value(event.LatestDate.Format(dateFmt)), a.Value(event.LatestDate.Format(formDateLayout)),
), ),
e.Br(), e.Br(),
@ -240,7 +240,7 @@ func genString() (string, error) {
return buf.String(), nil return buf.String(), nil
} }
const dateFmt = "2006-01-02" const formDateLayout = "2006-01-02"
func main() { func main() {
addr := flag.String("address", ":8080", "bind address for HTTP server as host:port") addr := flag.String("address", ":8080", "bind address for HTTP server as host:port")

View File

@ -99,7 +99,7 @@ type CreateEventResult struct {
AlphaID, AdminCode string 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) { func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result CreateEventResult, err error) {
conn := s.pool.Get(ctx) conn := s.pool.Get(ctx)
@ -123,8 +123,8 @@ func (s *Store) CreateEvent(ctx context.Context, cmd CreateEventCommand) (result
adminCode, adminCode,
cmd.Name, cmd.Name,
cmd.Description, cmd.Description,
cmd.EarliestDate.Format(dateFmt), cmd.EarliestDate.Format(dbDateLayout),
cmd.LatestDate.Format(dateFmt), cmd.LatestDate.Format(dbDateLayout),
) )
if err != nil { if err != nil {
return return
@ -165,11 +165,11 @@ func (s *Store) GetEvent(ctx context.Context, query GetEventQuery) (GetEventResu
latestDateString := stmt.ColumnText(3) latestDateString := stmt.ColumnText(3)
var err error var err error
result.EarliestDate, err = time.Parse(dateFmt, earliestDateString) result.EarliestDate, err = time.Parse(dbDateLayout, earliestDateString)
if err != nil { if err != nil {
return err return err
} }
result.LatestDate, err = time.Parse(dateFmt, latestDateString) result.LatestDate, err = time.Parse(dbDateLayout, latestDateString)
return err return err
}, query.AlphaID) }, query.AlphaID)
if err != nil { if err != nil {