We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp.toDate()
The implementation for Timestamp.toDate() is using .ceil() for the nanos component. This cause a difference of 1ms in this case:
.ceil()
nanos
Go's version:
ts := ×tamppb.Timestamp{ Seconds: int64(0), Nanos: int32(1), } fmt.Printf("%d\n", ts.AsTime().UnixMilli()) // Will output "0"
Typescript's version:
const ts: Timestamp = { seconds: BigInt(0), nanos: 1, } console.log(Timestamp.toDate(ts).getTime()); // Will output "1"
Change this function:
protobuf-ts/packages/plugin/src/message-type-extensions/well-known-types.ts
Lines 215 to 217 in 8a508df
To use Math.floor() instead of Math.ceil() like this:
Math.floor()
Math.ceil()
function toDate(message: ${Timestamp}): Date { return new Date(${PbLong}.from(message.seconds).toNumber() * 1000 + Math.floor(message.nanos / 1000000)); }
The text was updated successfully, but these errors were encountered:
I'll try to provide a working PR over the weekend for this if it's a valid concern.
Sorry, something went wrong.
No branches or pull requests
Issue Description
The implementation for
Timestamp.toDate()
is using.ceil()
for thenanos
component. This cause a difference of 1ms in this case:Go's version:
Typescript's version:
Proposed Changes
Change this function:
protobuf-ts/packages/plugin/src/message-type-extensions/well-known-types.ts
Lines 215 to 217 in 8a508df
To use
Math.floor()
instead ofMath.ceil()
like this:The text was updated successfully, but these errors were encountered: