diff --git a/internal/elements.go b/internal/elements.go index a0b6f36..19a8031 100644 --- a/internal/elements.go +++ b/internal/elements.go @@ -245,18 +245,24 @@ type GetContentType struct { Type string `xml:",chardata"` } -type Date string +type Time time.Time -func NewDate(t time.Time) Date { - return Date(t.Format(time.RFC1123Z)) +func (t *Time) UnmarshalText(b []byte) error { + tt, err := http.ParseTime(string(b)) + if err != nil { + return err + } + *t = Time(tt) + return nil } -func (d Date) Time() (time.Time, error) { - return http.ParseTime(string(d)) +func (t *Time) MarshalText() ([]byte, error) { + s := time.Time(*t).Format(time.RFC1123Z) + return []byte(s), nil } // https://tools.ietf.org/html/rfc4918#section-15.7 type GetLastModified struct { XMLName xml.Name `xml:"DAV: getlastmodified"` - LastModified Date `xml:",chardata"` + LastModified Time `xml:",chardata"` } diff --git a/server.go b/server.go index a99d6f5..d91bdea 100644 --- a/server.go +++ b/server.go @@ -238,7 +238,7 @@ var liveProps = map[xml.Name]PropfindFunc{ if fi.IsDir() { 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 }