Refactor ISO date, and datestamp format in constant
This commit is contained in:
parent
a3040cb195
commit
51540151ff
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"dev.tandem.ws/tandem/camper/pkg/database"
|
||||||
"dev.tandem.ws/tandem/camper/pkg/locale"
|
"dev.tandem.ws/tandem/camper/pkg/locale"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ func writeCellString(sb *strings.Builder, s string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeCellDate(sb *strings.Builder, t time.Time) {
|
func writeCellDate(sb *strings.Builder, t time.Time) {
|
||||||
sb.WriteString(fmt.Sprintf(" <table:table-cell table:style-name=\"ce1\" office:value-type=\"date\" office:date-value=\"%s\" calcext:value-type=\"date\"><text:p>%s</text:p></table:table-cell>\n", t.Format("2006-01-02"), t.Format("02/01/06")))
|
sb.WriteString(fmt.Sprintf(" <table:table-cell table:style-name=\"ce1\" office:value-type=\"date\" office:date-value=\"%s\" calcext:value-type=\"date\"><text:p>%s</text:p></table:table-cell>\n", t.Format(database.ISODateFormat), t.Format("02/01/06")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustWriteOdsResponse(w http.ResponseWriter, ods []byte, filename string) {
|
func mustWriteOdsResponse(w http.ResponseWriter, ods []byte, filename string) {
|
||||||
|
|
|
@ -16,7 +16,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
searchPathQuery = "set search_path to camper, public"
|
searchPathQuery = "set search_path to camper, public"
|
||||||
|
ISODateFormat = "2006-01-02"
|
||||||
|
ISODateTimeFormat = "2006-01-02 15:04:05"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrorIsNotFound(err error) bool {
|
func ErrorIsNotFound(err error) bool {
|
||||||
|
|
|
@ -120,13 +120,13 @@ func (v *Validator) CheckValidPostalCode(ctx context.Context, conn *database.Con
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Validator) CheckValidDate(field *Input, message string) bool {
|
func (v *Validator) CheckValidDate(field *Input, message string) bool {
|
||||||
_, err := time.Parse("2006-01-02", field.Val)
|
_, err := time.Parse(database.ISODateFormat, field.Val)
|
||||||
return v.Check(field, err == nil, message)
|
return v.Check(field, err == nil, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Validator) CheckDateAfter(field *Input, beforeField *Input, message string) bool {
|
func (v *Validator) CheckDateAfter(field *Input, beforeField *Input, message string) bool {
|
||||||
date, _ := time.Parse("2006-01-02", field.Val)
|
date, _ := time.Parse(database.ISODateFormat, field.Val)
|
||||||
before, _ := time.Parse("2006-01-02", beforeField.Val)
|
before, _ := time.Parse(database.ISODateFormat, beforeField.Val)
|
||||||
return v.Check(field, date.After(before), message)
|
return v.Check(field, date.After(before), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ func CollectSeasonCalendar(ctx context.Context, company *auth.Company, conn *dat
|
||||||
from generate_series($2, $3, interval '1 day') as t(day)
|
from generate_series($2, $3, interval '1 day') as t(day)
|
||||||
left join season_calendar on season_range @> t.day::date
|
left join season_calendar on season_range @> t.day::date
|
||||||
left join season on season.season_id = season_calendar.season_id and company_id = $4
|
left join season on season.season_id = season_calendar.season_id and company_id = $4
|
||||||
`, UnsetColor, firstDay.Format("2006-01-02 15:04:05"), lastDay.Format("2006-01-02 15:04:05"), company.ID)
|
`, UnsetColor, firstDay.Format(database.ISODateTimeFormat), lastDay.Format(database.ISODateTimeFormat), company.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"dev.tandem.ws/tandem/camper/pkg/auth"
|
"dev.tandem.ws/tandem/camper/pkg/auth"
|
||||||
"dev.tandem.ws/tandem/camper/pkg/build"
|
"dev.tandem.ws/tandem/camper/pkg/build"
|
||||||
|
"dev.tandem.ws/tandem/camper/pkg/database"
|
||||||
httplib "dev.tandem.ws/tandem/camper/pkg/http"
|
httplib "dev.tandem.ws/tandem/camper/pkg/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ func mustRenderLayout(w io.Writer, user *auth.User, company *auth.Company, templ
|
||||||
return formatPrice(price, user.Locale.Language, user.Locale.CurrencyPattern, company.DecimalDigits, company.CurrencySymbol)
|
return formatPrice(price, user.Locale.Language, user.Locale.CurrencyPattern, company.DecimalDigits, company.CurrencySymbol)
|
||||||
},
|
},
|
||||||
"formatDate": func(time time.Time) template.HTML {
|
"formatDate": func(time time.Time) template.HTML {
|
||||||
return template.HTML(`<time datetime="` + time.Format("2006-01-02") + `">` + time.Format("02/01/2006") + "</time>")
|
return template.HTML(`<time datetime="` + time.Format(database.ISODateFormat) + `">` + time.Format("02/01/2006") + "</time>")
|
||||||
},
|
},
|
||||||
"queryEscape": func(s string) string {
|
"queryEscape": func(s string) string {
|
||||||
return url.QueryEscape(s)
|
return url.QueryEscape(s)
|
||||||
|
|
Loading…
Reference in New Issue