-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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:
class Timestamp extends Date {
#nanoseconds = 0;
setNanoseconds(nanoseconds: number) {
this.#nanoseconds = nanoseconds;
}
getNanoseconds() {
return this.#nanoseconds;
}
}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.