Skip to content
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

Ruby version Timestamp.from_time feels like there should be a class method #8424

Closed
tmtrademarked opened this issue Mar 23, 2021 · 1 comment
Labels

Comments

@tmtrademarked
Copy link

tmtrademarked commented Mar 23, 2021

What language does this apply to?
Generated Ruby code

Describe the problem you are trying to solve.
Working with timestamps is somewhat awkward. To create a protobuf timestamp from Ruby time objects, you have to do the following:

ts = Google::Protobuf::Timestamp.new
ts.from_time(Time.now) # returns the nanos rather than the Timestamp itself.

Describe the solution you'd like
It seems like it would be easier if the Timestamp class just defined a class method as well as an instance method. Something like:

def self.from_time(time)
  return if time.nil?
  new(seconds: time.seconds, nanos: time.nsec)
end

This would allow developers to create timestamp objects in a slightly more natural syntax:

ts = Google::Protobuf::Timestamp.from_time(Time.now)
@haberman haberman added the ruby label Apr 9, 2021
@deannagarcia
Copy link
Member

This functionality was added in #8562, so newer forms of protobuf should have it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants