You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today Protoscript deserializes timestamps into an object in the shape { seconds: bigint, nanoseconds: number }.
We could instead deserialize timestamps into JavaScript Date objects. The only unclear pieces are:
JS Date objects lack some of the precision of the object form. Specifically, JS Date's can handle up to 3 digit of ms precision, vs the timestamp object's 9 digits of nanosecond precision.
This would be a breaking change for user's source code. The wire format would be unchanged.
The above could be mitigated with an opt-in or opt-out flag. I'm inclined to make this the default behavior, and potentially consider an opt-out flag.
Altternatively, ProtoScript could create a subclass Timestamp from Date. That subclass could then be used anywhere a Date is used, and optionally provide the nanoseconds for code paths aware of Timestamp. Eg:
tatethurston
changed the title
Deserialize Timestamps into Date objects
Deserialize Timestamps (google.protobuf.Timestamp) into Date objects
Oct 18, 2023
Yeah agreed that automatic deserialization to Date is the best DX -- I'm inclined to make that the default. And then I'm open to supporting a config option to disable deserialization to Date, though I might wait until someone requests that. I think it's unlikely that JS users will be looking to use protobuf timestamps with granularity smaller than 1ms, but I'm open to being wrong.
Today Protoscript deserializes timestamps into an object in the shape
{ seconds: bigint, nanoseconds: number }
.We could instead deserialize timestamps into JavaScript
Date
objects. The only unclear pieces are:The above could be mitigated with an opt-in or opt-out flag. I'm inclined to make this the default behavior, and potentially consider an opt-out flag.
Altternatively, ProtoScript could create a subclass
Timestamp
fromDate
. That subclass could then be used anywhere a Date is used, and optionally provide the nanoseconds for code paths aware ofTimestamp
. Eg:Or something more clever using the constructor arguments -- but I'm considered about edge cases and maintenance there.
Please comment or like this issue if you're a user and want to see this change land.
The text was updated successfully, but these errors were encountered: