Add option to convert Timestamp WKT to DateTime
Closed this issue · 4 comments
google.protobuf.Timestamp
should be generated to Dart's DateTime
, because if I use generated messages for saving objects to Firestore, it does not know how to convert it to a Firestore's timestamp
object, and, obviously, it does not know how to query on it.
I would do it myself but I don't know why it must be changed.
You should be able to convert to a DateTime with .toDateTime()
: https://github.com/google/protobuf.dart/blob/master/protobuf/lib/src/protobuf/mixins/well_known.dart#L156
A google.protobuf.Timestamp
has nano-second resolution. DateTime
has millisecond resolution - so they should not be converted automatically.
Closing as this is not an issue with the library. Please feel free to reopen if you disagree.
You should be able to convert to a DateTime with
.toDateTime()
: https://github.com/google/protobuf.dart/blob/master/protobuf/lib/src/protobuf/mixins/well_known.dart#L156A
google.protobuf.Timestamp
has nano-second resolution.DateTime
has millisecond resolution - so they should not be converted automatically.
Yes, but when you do toProto3Json()
, it will serialize Timestamp
to ISO string, and If you want to send that to Firestore, it will treat it as an string, not as a firestore timestamp
I believe that is mandated by the protobuf standard: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto#L106