Skip to content

Commit

Permalink
Support time format with the Z suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
joec4i committed Sep 19, 2022
1 parent 9e8ac9b commit 414ccaa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,16 +1114,13 @@ func (c *Connection) Objects(ctx context.Context, container string, opts *Object
object.ContentType = "application/directory"
}
if object.ServerLastModified != "" {
// 2012-11-11T14:49:47.887250
// e.g. 2012-11-11T14:49:47, 2012-11-11T14:49:47Z, 2012-11-11T14:49:47.887250, or 2012-11-11T14:49:47.887250Z
// Remove the Z suffix and fractional seconds if present. This then keeps it consistent with Object which
// can only return timestamps accurate to 1 second
//
// Remove fractional seconds if present. This
// then keeps it consistent with Object
// which can only return timestamps accurate
// to 1 second
//
// The TimeFormat will parse fractional
// seconds if desired though
datetime := strings.SplitN(object.ServerLastModified, ".", 2)[0]
// The TimeFormat will parse fractional seconds if desired though
lastModified := strings.TrimSuffix(object.ServerLastModified, "Z")
datetime := strings.SplitN(lastModified, ".", 2)[0]
object.LastModified, err = time.Parse(TimeFormat, datetime)
if err != nil {
return nil, err
Expand Down

0 comments on commit 414ccaa

Please sign in to comment.