rust-protobuf icon indicating copy to clipboard operation
rust-protobuf copied to clipboard

Current Timestamp

Open Jasperav opened this issue 5 years ago • 8 comments

Timestamp is a WellKnownType. I am confused how to fill this struct with the current time. Seconds is implemented as i64, and nano is implemented as i32. Are they both combined a time? Is there any way I can say: Give me a Timestamp where the time is equal to now (epoch time)?

Jasperav avatar Feb 20 '20 20:02 Jasperav

This question does not apply to rust-protobuf implementation. This question relates to protobuf itself, or rather to the message that was developed by Google programmers.

Read the contents of the timestamp.proto file and you will understand everything.

heretic13 avatar Mar 12 '20 13:03 heretic13

Read the contents of the timestamp.proto file and you will understand everything.

Understanding how it's implemented is indeed not that hard, implementing is hard.

This is the way Apple implemented it for Swift: https://github.com/apple/swift-protobuf/blob/6dd839744095363620b99f247a46714e7123163b/Sources/SwiftProtobuf/Google_Protobuf_Timestamp%2BExtensions.swift#L243.

It is also implemented natively by many other languages: https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/timestamp.

I also asked the Reddit community how to solve this problem: https://www.reddit.com/r/rust/comments/fde7qq/create_current_timestamp_in_rust_protobuf/, but also no answers.

So I think it is harder than it looks like and I hope it will be added to this crate instead of many different implementations by many different developers.

Jasperav avatar Mar 13 '20 13:03 Jasperav

There is nothing complicated to implement. If the programmer cannot write such a function himself, then he chose the profession incorrectly.

heretic13 avatar Mar 13 '20 14:03 heretic13

There is nothing complicated to implement. If the programmer cannot write such a function himself, then he chose the profession incorrectly.

Hahaha, that is a good laugh. If it's so easy, why don't create a PR and help out the community, instead of bashing other people?

Jasperav avatar Mar 13 '20 14:03 Jasperav

655adb7d9cee66b90a551ab3b0e9b54ebf4b0256 adds some utilities on Timestamp type.

This is added in master only at the moment.

I'd appreciate:

  • some code review
  • feedback, whether we need it in stable branch

stepancheg avatar Apr 12 '20 02:04 stepancheg

@stepancheg does this mean thatprotobuf-codegen-pure on master should support usage of Timestamp after import "google/protobuf/timestamp.proto";?

I'm probably doing something wrong, but I couldn't get it to work.

thread 'main' panicked at 'protobuf codegen failed: Custom { kind: Other, error: "protobuf path \"google/protobuf/timestamp.proto\" is not found in import path [\"proto\"]" }', build.rs:12:5

clintfred avatar Apr 29 '20 21:04 clintfred

I am unable to import Timestamp in my proto file. Is Timestamp.proto included int he crate? or do I have to pull down google proto repo to import it?

yshahin avatar Nov 06 '20 00:11 yshahin

@yshahin I can confirm that this does work without much effort in 2.17 with protobuf-codegen-pure (it started working a couple releases ago). If you are using something older you have to do more to get timestamp working.

clintfred avatar Nov 06 '20 16:11 clintfred