mirror of
https://github.com/rclone/rclone.git
synced 2025-12-20 02:03:17 +00:00
vendor: add github.com/putdotio/go-putio for putio client
This commit is contained in:
committed by
Nick Craig-Wood
parent
8159658e67
commit
566aa0fca7
33
vendor/github.com/putdotio/go-putio/putio/time.go
generated
vendored
Normal file
33
vendor/github.com/putdotio/go-putio/putio/time.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
package putio
|
||||
|
||||
import "time"
|
||||
|
||||
// Time is a wrapper around time.Time that can be unmarshalled from a JSON
|
||||
// string formatted as "2016-04-19T15:44:42". All methods of time.Time can be
|
||||
// called on Time.
|
||||
type Time struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (t *Time) String() string {
|
||||
return t.Time.String()
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
// put.io API has inconsistent time layouts for different endpoints, such
|
||||
// as /files and /events
|
||||
var timeLayouts = []string{`"2006-01-02T15:04:05"`, `"2006-01-02 15:04:05"`}
|
||||
|
||||
s := string(data)
|
||||
var err error
|
||||
var tm time.Time
|
||||
for _, layout := range timeLayouts {
|
||||
tm, err = time.ParseInLocation(layout, s, time.UTC)
|
||||
if err == nil {
|
||||
t.Time = tm
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user