inetrnal: rename Date to Time, make it a Text{Marshaler,Unmarshaler}

This commit is contained in:
Simon Ser 2020-01-15 19:32:59 +01:00
parent 3d37e49ca0
commit ae0541654a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 13 additions and 7 deletions

View File

@ -245,18 +245,24 @@ type GetContentType struct {
Type string `xml:",chardata"` Type string `xml:",chardata"`
} }
type Date string type Time time.Time
func NewDate(t time.Time) Date { func (t *Time) UnmarshalText(b []byte) error {
return Date(t.Format(time.RFC1123Z)) tt, err := http.ParseTime(string(b))
if err != nil {
return err
}
*t = Time(tt)
return nil
} }
func (d Date) Time() (time.Time, error) { func (t *Time) MarshalText() ([]byte, error) {
return http.ParseTime(string(d)) s := time.Time(*t).Format(time.RFC1123Z)
return []byte(s), nil
} }
// https://tools.ietf.org/html/rfc4918#section-15.7 // https://tools.ietf.org/html/rfc4918#section-15.7
type GetLastModified struct { type GetLastModified struct {
XMLName xml.Name `xml:"DAV: getlastmodified"` XMLName xml.Name `xml:"DAV: getlastmodified"`
LastModified Date `xml:",chardata"` LastModified Time `xml:",chardata"`
} }

View File

@ -238,7 +238,7 @@ var liveProps = map[xml.Name]PropfindFunc{
if fi.IsDir() { if fi.IsDir() {
return nil, &HTTPError{Code: http.StatusNotFound} return nil, &HTTPError{Code: http.StatusNotFound}
} }
return &internal.GetLastModified{LastModified: internal.NewDate(fi.ModTime())}, nil return &internal.GetLastModified{LastModified: internal.Time(fi.ModTime())}, nil
}, },
// TODO: getetag // TODO: getetag
} }