package lulu import ( "fmt" "time" ) type Date time.Time func ParseDate(s string) (Date, error) { t, err := time.Parse(time.DateOnly, s) return Date(t), err } func MustParseDate(s string) Date { d, err := ParseDate(s) if err != nil { panic(fmt.Sprintf("lulu.ParseDate(%q): %v", s, err)) } return d } func (d Date) String() string { return time.Time(d).Format(time.DateOnly) } func (d *Date) UnmarshalText(text []byte) error { nd, err := ParseDate(string(text)) if err != nil { return err } *d = nd return nil } func (d Date) MarshalText() ([]byte, error) { s := time.Time(d).Format(time.DateOnly) return []byte(s), nil }