forked from TrueCloudLab/rclone
webdav: add a new time format #1952
This commit is contained in:
parent
821be5ebed
commit
59a8108fc3
1 changed files with 16 additions and 9 deletions
|
@ -11,8 +11,6 @@ import (
|
||||||
const (
|
const (
|
||||||
// Wed, 27 Sep 2017 14:28:34 GMT
|
// Wed, 27 Sep 2017 14:28:34 GMT
|
||||||
timeFormat = time.RFC1123
|
timeFormat = time.RFC1123
|
||||||
// Fri, 05 Jan 2018 14:14:38 +0000 (as used by mydrive.ch)
|
|
||||||
timeFormatZ = time.RFC1123Z
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Multistatus contains responses returned from an HTTP 207 return code
|
// Multistatus contains responses returned from an HTTP 207 return code
|
||||||
|
@ -133,6 +131,13 @@ func (t *Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
return e.EncodeElement(timeString, start)
|
return e.EncodeElement(timeString, start)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Possible time formats to parse the time with
|
||||||
|
var timeFormats = []string{
|
||||||
|
timeFormat, // Wed, 27 Sep 2017 14:28:34 GMT (as per RFC)
|
||||||
|
time.RFC1123Z, // Fri, 05 Jan 2018 14:14:38 +0000 (as used by mydrive.ch)
|
||||||
|
time.UnixDate, // Wed May 17 15:31:58 UTC 2017 (as used in an internal server)
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalXML turns XML into a Time
|
// UnmarshalXML turns XML into a Time
|
||||||
func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
var v string
|
var v string
|
||||||
|
@ -140,13 +145,15 @@ func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newT, err := time.Parse(timeFormat, v)
|
|
||||||
if err != nil {
|
// Parse the time format in multiple possible ways
|
||||||
newT, err = time.Parse(timeFormatZ, v)
|
var newT time.Time
|
||||||
if err != nil {
|
for _, timeFormat := range timeFormats {
|
||||||
return err
|
newT, err = time.Parse(timeFormat, v)
|
||||||
}
|
if err == nil {
|
||||||
}
|
|
||||||
*t = Time(newT)
|
*t = Time(newT)
|
||||||
return nil
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue