diff --git a/storage/bucket.go b/storage/bucket.go index 2746ae459585..55ad121c2852 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -28,12 +28,12 @@ import ( "cloud.google.com/go/internal/optional" "cloud.google.com/go/internal/trace" storagepb "cloud.google.com/go/storage/internal/apiv2/stubs" - "github.com/googleapis/go-type-adapters/adapters" "google.golang.org/api/googleapi" "google.golang.org/api/iamcredentials/v1" "google.golang.org/api/iterator" "google.golang.org/api/option" raw "google.golang.org/api/storage/v1" + dpb "google.golang.org/genproto/googleapis/type/date" "google.golang.org/protobuf/proto" ) @@ -1613,13 +1613,13 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle { } if !r.Condition.CreatedBefore.IsZero() { - rr.Condition.CreatedBefore = adapters.TimeToProtoDate(r.Condition.CreatedBefore) + rr.Condition.CreatedBefore = timeToProtoDate(r.Condition.CreatedBefore) } if !r.Condition.CustomTimeBefore.IsZero() { - rr.Condition.CustomTimeBefore = adapters.TimeToProtoDate(r.Condition.CustomTimeBefore) + rr.Condition.CustomTimeBefore = timeToProtoDate(r.Condition.CustomTimeBefore) } if !r.Condition.NoncurrentTimeBefore.IsZero() { - rr.Condition.NoncurrentTimeBefore = adapters.TimeToProtoDate(r.Condition.NoncurrentTimeBefore) + rr.Condition.NoncurrentTimeBefore = timeToProtoDate(r.Condition.NoncurrentTimeBefore) } rl.Rule = append(rl.Rule, rr) } @@ -1716,13 +1716,13 @@ func toLifecycleFromProto(rl *storagepb.Bucket_Lifecycle) Lifecycle { } if rr.GetCondition().GetCreatedBefore() != nil { - r.Condition.CreatedBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetCreatedBefore()) + r.Condition.CreatedBefore = protoDateToUTCTime(rr.GetCondition().GetCreatedBefore()) } if rr.GetCondition().GetCustomTimeBefore() != nil { - r.Condition.CustomTimeBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetCustomTimeBefore()) + r.Condition.CustomTimeBefore = protoDateToUTCTime(rr.GetCondition().GetCustomTimeBefore()) } if rr.GetCondition().GetNoncurrentTimeBefore() != nil { - r.Condition.NoncurrentTimeBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetNoncurrentTimeBefore()) + r.Condition.NoncurrentTimeBefore = protoDateToUTCTime(rr.GetCondition().GetNoncurrentTimeBefore()) } l.Rules = append(l.Rules, r) } @@ -2236,3 +2236,28 @@ func (rpo RPO) String() string { return rpoUnknown } } + +// protoDateToUTCTime returns a new Time based on the google.type.Date, in UTC. +// +// Hours, minutes, seconds, and nanoseconds are set to 0. +func protoDateToUTCTime(d *dpb.Date) time.Time { + return protoDateToTime(d, time.UTC) +} + +// protoDateToTime returns a new Time based on the google.type.Date and provided +// *time.Location. +// +// Hours, minutes, seconds, and nanoseconds are set to 0. +func protoDateToTime(d *dpb.Date, l *time.Location) time.Time { + return time.Date(int(d.GetYear()), time.Month(d.GetMonth()), int(d.GetDay()), 0, 0, 0, 0, l) +} + +// timeToProtoDate returns a new google.type.Date based on the provided time.Time. +// The location is ignored, as is anything more precise than the day. +func timeToProtoDate(t time.Time) *dpb.Date { + return &dpb.Date{ + Year: int32(t.Year()), + Month: int32(t.Month()), + Day: int32(t.Day()), + } +} diff --git a/storage/go.mod b/storage/go.mod index 50d18224b4fc..36e413806e11 100644 --- a/storage/go.mod +++ b/storage/go.mod @@ -10,7 +10,6 @@ require ( github.com/google/go-cmp v0.5.8 github.com/google/uuid v1.3.0 github.com/googleapis/gax-go/v2 v2.4.0 - github.com/googleapis/go-type-adapters v1.0.0 golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f google.golang.org/api v0.85.0 diff --git a/storage/go.sum b/storage/go.sum index 246c7c6f9231..ab45b0253f37 100644 --- a/storage/go.sum +++ b/storage/go.sum @@ -179,7 +179,6 @@ github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/Oth github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM= github.com/googleapis/gax-go/v2 v2.4.0 h1:dS9eYAjhrE2RjmzYw2XAPvcXfmcQLtFEQWn0CR82awk= github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c= -github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=