I am creating a Go application which will use GRPC and protobuf. My RPC service shall take a message containing the type google.protobuf.Timestamp
, parse it and eventually save it in a database or perform some more operations on it.
I am confused as to what is considered valid input for the type google.protobuf.Timestamp
. I wish to use the following format for the datetimestamp with the timezone offset.
2019-02-15T13:00:00+01:00
Here is the proto file I am using.
syntax = "proto3"
package example;
import "google/protobuf/timestamp.proto"
service Tester {
rpc ParseDateTimeStamp(TSRequest) returns (TSReply) {}
}
message TSRequest {
google.protobuf.Timestamp dts = 1;
}
message TSReply {
string message = 1;
}
The issue is that when I send a message to the GRPC server containing the datetimestamp. I would expect that the type *tsbp.Timestamp
for the 2019-02-15T13:00:00+01:00
datetimestamp given to be valid and give me the appropriate seconds from epoch. (After invoking GetSeconds()
from the timestamp.go)
Invoking ptypes.TimestampString(ts *tspb.Timestamp)
returns 1970-01-01T00:00:00Z
for the example input above.
Does the google.protobuf.Timestamp
accept datetimestamps with the +- offset?
Or do I have to have the input in a String type and then parse to time.Time
with time.Format
instead of using the timestamp variable type in protobuf? If so could you provide an example of this?
TSReply
message - do you want it to include the original timezone offset? If so, your input value ofptype.Timestamp
does not have the storage of a TZ value, so any offset would need to be included in an extra field. – colm.anseo