-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add pbtime util package #11085
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @robert-zaremba. I wonder if this maybe does fit in the scope of cosmos-proto as it is pretty generic. @fdymylja would you feel comfortable including it there?
func IsZero(t *tspb.Timestamp) bool { | ||
return t == nil || t.Nanos == 0 && t.Seconds == 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't generically true. it's sufficient if we assume that the time is in the future, but technically 1970-01-01 is a valid timestamp. generically IsZero
is equivalent to t == nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't do a validation. The goal is to make a canonical zero value which work with a non nil version of tspb.Timestamp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's not zero. We can't use this to infer that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's zero value of tspb.Timestamp
and I thought that yesterday we said to add a support for a non nil zero value.
That being said, my if we can change non nil to nil in proto and handle that in a normal way, then that would be my preference.
pbtime/cmp.go
Outdated
return 1 | ||
} | ||
|
||
func Add(t *tspb.Timestamp, d time.Duration) *tspb.Timestamp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use durationpb
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,. we can have both: time.Duration
and durationpb
TBH, I think ideally you'd want all the I don't feel the sdk is the correct place for this package, I don't even think cosmos-proto is, Ideally you'd want these upstreamed to go-protobuf (as methods on those types and not as utility function). But if I had to choose between sdk or cosmos-proto, then better have those in a |
Co-authored-by: Aaron Craelius <aaron@regen.network>
We can add them later, when needed. For the moment I mostly need |
I've updated the PR to:
|
I think moving it to cosmos-proto is a good idea. Anyone against? |
Moving to cosmos-proto makes sense |
OK, will keep this PR open until I will move it (plan: tomorrow) to let other comment on other things. |
Moved to cosmos/cosmos-proto#60 |
Description
Adding pbtime package bring more higher level functionality to protobuf.Timestamp (notably comparison).
With new proto directions we are going away from go stdlib time.Time.
Note, I put it into root, but maybe there is a better place?
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change