-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Description
Issue Description
The implementation for Timestamp.toDate() is using .ceil() for the nanos component. This cause a difference of 1ms in this case:
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"Proposed Changes
Change this function:
protobuf-ts/packages/plugin/src/message-type-extensions/well-known-types.ts
Lines 215 to 217 in 8a508df
| function toDate(message: ${Timestamp}): Date { | |
| return new Date(${PbLong}.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000)); | |
| } |
To use Math.floor() instead of Math.ceil() like this:
function toDate(message: ${Timestamp}): Date {
return new Date(${PbLong}.from(message.seconds).toNumber() * 1000 + Math.floor(message.nanos / 1000000));
}Metadata
Metadata
Assignees
Labels
No labels