@@ -28,12 +28,12 @@ import (
2828 "cloud.google.com/go/internal/optional"
2929 "cloud.google.com/go/internal/trace"
3030 storagepb "cloud.google.com/go/storage/internal/apiv2/stubs"
31- "github.com/googleapis/go-type-adapters/adapters"
3231 "google.golang.org/api/googleapi"
3332 "google.golang.org/api/iamcredentials/v1"
3433 "google.golang.org/api/iterator"
3534 "google.golang.org/api/option"
3635 raw "google.golang.org/api/storage/v1"
36+ dpb "google.golang.org/genproto/googleapis/type/date"
3737 "google.golang.org/protobuf/proto"
3838)
3939
@@ -1613,13 +1613,13 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle {
16131613 }
16141614
16151615 if ! r .Condition .CreatedBefore .IsZero () {
1616- rr .Condition .CreatedBefore = adapters . TimeToProtoDate (r .Condition .CreatedBefore )
1616+ rr .Condition .CreatedBefore = timeToProtoDate (r .Condition .CreatedBefore )
16171617 }
16181618 if ! r .Condition .CustomTimeBefore .IsZero () {
1619- rr .Condition .CustomTimeBefore = adapters . TimeToProtoDate (r .Condition .CustomTimeBefore )
1619+ rr .Condition .CustomTimeBefore = timeToProtoDate (r .Condition .CustomTimeBefore )
16201620 }
16211621 if ! r .Condition .NoncurrentTimeBefore .IsZero () {
1622- rr .Condition .NoncurrentTimeBefore = adapters . TimeToProtoDate (r .Condition .NoncurrentTimeBefore )
1622+ rr .Condition .NoncurrentTimeBefore = timeToProtoDate (r .Condition .NoncurrentTimeBefore )
16231623 }
16241624 rl .Rule = append (rl .Rule , rr )
16251625 }
@@ -1716,13 +1716,13 @@ func toLifecycleFromProto(rl *storagepb.Bucket_Lifecycle) Lifecycle {
17161716 }
17171717
17181718 if rr .GetCondition ().GetCreatedBefore () != nil {
1719- r .Condition .CreatedBefore = adapters . ProtoDateToUTCTime (rr .GetCondition ().GetCreatedBefore ())
1719+ r .Condition .CreatedBefore = protoDateToUTCTime (rr .GetCondition ().GetCreatedBefore ())
17201720 }
17211721 if rr .GetCondition ().GetCustomTimeBefore () != nil {
1722- r .Condition .CustomTimeBefore = adapters . ProtoDateToUTCTime (rr .GetCondition ().GetCustomTimeBefore ())
1722+ r .Condition .CustomTimeBefore = protoDateToUTCTime (rr .GetCondition ().GetCustomTimeBefore ())
17231723 }
17241724 if rr .GetCondition ().GetNoncurrentTimeBefore () != nil {
1725- r .Condition .NoncurrentTimeBefore = adapters . ProtoDateToUTCTime (rr .GetCondition ().GetNoncurrentTimeBefore ())
1725+ r .Condition .NoncurrentTimeBefore = protoDateToUTCTime (rr .GetCondition ().GetNoncurrentTimeBefore ())
17261726 }
17271727 l .Rules = append (l .Rules , r )
17281728 }
@@ -2236,3 +2236,28 @@ func (rpo RPO) String() string {
22362236 return rpoUnknown
22372237 }
22382238}
2239+
2240+ // protoDateToUTCTime returns a new Time based on the google.type.Date, in UTC.
2241+ //
2242+ // Hours, minutes, seconds, and nanoseconds are set to 0.
2243+ func protoDateToUTCTime (d * dpb.Date ) time.Time {
2244+ return protoDateToTime (d , time .UTC )
2245+ }
2246+
2247+ // protoDateToTime returns a new Time based on the google.type.Date and provided
2248+ // *time.Location.
2249+ //
2250+ // Hours, minutes, seconds, and nanoseconds are set to 0.
2251+ func protoDateToTime (d * dpb.Date , l * time.Location ) time.Time {
2252+ return time .Date (int (d .GetYear ()), time .Month (d .GetMonth ()), int (d .GetDay ()), 0 , 0 , 0 , 0 , l )
2253+ }
2254+
2255+ // timeToProtoDate returns a new google.type.Date based on the provided time.Time.
2256+ // The location is ignored, as is anything more precise than the day.
2257+ func timeToProtoDate (t time.Time ) * dpb.Date {
2258+ return & dpb.Date {
2259+ Year : int32 (t .Year ()),
2260+ Month : int32 (t .Month ()),
2261+ Day : int32 (t .Day ()),
2262+ }
2263+ }
0 commit comments