From 3bf8b296d88d5edf61296f96592dd1dfebfc8046 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Sat, 7 Sep 2024 12:29:09 -0700 Subject: [PATCH] fix: format timestamp responses with RFC3339TimeFormat This fixes the rest of the s3reponse types to marshall the time field in RFC3339TimeFormat when MarshalXML called. Fixes #782 --- s3response/s3response.go | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/s3response/s3response.go b/s3response/s3response.go index 1fd5b96..c17796f 100644 --- a/s3response/s3response.go +++ b/s3response/s3response.go @@ -77,6 +77,23 @@ type GetObjectAttributesResult struct { ObjectParts *ObjectParts } +func (r GetObjectAttributesResult) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + type Alias GetObjectAttributesResult + aux := &struct { + LastModified *string `xml:"LastModified"` + *Alias + }{ + Alias: (*Alias)(&r), + } + + if r.LastModified != nil { + formattedTime := r.LastModified.Format(RFC3339TimeFormat) + aux.LastModified = &formattedTime + } + + return e.EncodeElement(aux, start) +} + type ObjectParts struct { PartNumberMarker int NextPartNumberMarker int @@ -261,6 +278,20 @@ type ListAllMyBucketsEntry struct { CreationDate time.Time } +func (r ListAllMyBucketsEntry) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + type Alias ListAllMyBucketsEntry + aux := &struct { + CreationDate string `xml:"LastModified"` + *Alias + }{ + Alias: (*Alias)(&r), + } + + aux.CreationDate = r.CreationDate.Format(RFC3339TimeFormat) + + return e.EncodeElement(aux, start) +} + type ListAllMyBucketsList struct { Bucket []ListAllMyBucketsEntry } @@ -276,6 +307,20 @@ type CopyObjectResult struct { ETag string } +func (r CopyObjectResult) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + type Alias CopyObjectResult + aux := &struct { + LastModified string `xml:"LastModified"` + *Alias + }{ + Alias: (*Alias)(&r), + } + + aux.LastModified = r.LastModified.Format(RFC3339TimeFormat) + + return e.EncodeElement(aux, start) +} + type AccessControlPolicy struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"` Owner CanonicalUser