mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
internal: use http.TimeFormat to marshal Time values
This commit is contained in:
parent
ed52608852
commit
8efde26ef9
@ -321,7 +321,7 @@ func (t *Time) UnmarshalText(b []byte) error {
|
||||
}
|
||||
|
||||
func (t *Time) MarshalText() ([]byte, error) {
|
||||
s := time.Time(*t).Format(time.RFC1123Z)
|
||||
s := time.Time(*t).UTC().Format(http.TimeFormat)
|
||||
return []byte(s), nil
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// https://tools.ietf.org/html/rfc4918#section-9.6.2
|
||||
@ -32,3 +34,26 @@ func TestMultistatus_Get_error(t *testing.T) {
|
||||
t.Errorf("HTTPError.Code = %v, expected 423", httpErr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeRoundTrip(t *testing.T) {
|
||||
now := Time(time.Now().UTC())
|
||||
want, err := now.MarshalText()
|
||||
if err != nil {
|
||||
t.Fatalf("could not marshal time: %+v", err)
|
||||
}
|
||||
|
||||
var got Time
|
||||
err = got.UnmarshalText(want)
|
||||
if err != nil {
|
||||
t.Fatalf("could not unmarshal time: %+v", err)
|
||||
}
|
||||
|
||||
raw, err := got.MarshalText()
|
||||
if err != nil {
|
||||
t.Fatalf("could not marshal back: %+v", err)
|
||||
}
|
||||
|
||||
if got, want := raw, want; !bytes.Equal(got, want) {
|
||||
t.Fatalf("invalid round-trip:\ngot= %s\nwant=%s", got, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user