Refactor ISO date, and datestamp format in constant

This commit is contained in:
jordi fita mas 2024-01-31 19:58:46 +01:00
parent a3040cb195
commit 51540151ff
5 changed files with 11 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"time"
"dev.tandem.ws/tandem/camper/pkg/database"
"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) {
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) {

View File

@ -17,6 +17,8 @@ import (
const (
searchPathQuery = "set search_path to camper, public"
ISODateFormat = "2006-01-02"
ISODateTimeFormat = "2006-01-02 15:04:05"
)
func ErrorIsNotFound(err error) bool {

View File

@ -120,13 +120,13 @@ func (v *Validator) CheckValidPostalCode(ctx context.Context, conn *database.Con
}
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)
}
func (v *Validator) CheckDateAfter(field *Input, beforeField *Input, message string) bool {
date, _ := time.Parse("2006-01-02", field.Val)
before, _ := time.Parse("2006-01-02", beforeField.Val)
date, _ := time.Parse(database.ISODateFormat, field.Val)
before, _ := time.Parse(database.ISODateFormat, beforeField.Val)
return v.Check(field, date.After(before), message)
}

View File

@ -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)
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
`, 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 {
return nil, err
}

View File

@ -23,6 +23,7 @@ import (
"dev.tandem.ws/tandem/camper/pkg/auth"
"dev.tandem.ws/tandem/camper/pkg/build"
"dev.tandem.ws/tandem/camper/pkg/database"
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)
},
"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 {
return url.QueryEscape(s)