Skip to content

Commit e649f77

Browse files
authored
WakuMessage.timestamp field must use nanoseconds (#606)
1 parent 2798376 commit e649f77

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Fixed
1919

2020
- Handle errors thrown by `bytesToUtf8`.
21+
- `WakuMessage.timestamp` field must use nanoseconds (was using microseconds).
2122

2223
### Removed
2324

src/lib/waku_message/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export class WakuMessage {
104104
{
105105
payload: _payload,
106106
timestampDeprecated: timestamp.valueOf() / 1000,
107-
// nanoseconds https://rfc.vac.dev/spec/14/
108-
timestamp: Long.fromNumber(timestamp.valueOf()).mul(1000),
107+
// milliseconds 10^-3 to nanoseconds 10^-9
108+
timestamp: Long.fromNumber(timestamp.valueOf()).mul(1_000_000),
109109
version,
110110
contentTopic,
111111
},
@@ -281,8 +281,8 @@ export class WakuMessage {
281281
// we catch the error and return undefined.
282282
try {
283283
if (this.proto.timestamp) {
284-
// nanoseconds https://rfc.vac.dev/spec/14/
285-
const timestamp = this.proto.timestamp.div(1000).toNumber();
284+
// nanoseconds 10^-9 to milliseconds 10^-3
285+
const timestamp = this.proto.timestamp.div(1_000_000).toNumber();
286286
return new Date(timestamp);
287287
}
288288

src/lib/waku_store/history_rpc.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,17 @@ export class HistoryRPC {
107107
} as protoV2Beta4.PagingInfo;
108108

109109
let startTime, endTime;
110-
if (params.startTime)
111-
startTime = Long.fromNumber(params.startTime.valueOf()).mul(1000);
112-
113-
if (params.endTime)
114-
endTime = Long.fromNumber(params.endTime.valueOf()).mul(1000);
115-
110+
if (params.startTime) {
111+
// milliseconds 10^-3 to nanoseconds 10^-9
112+
startTime = Long.fromNumber(params.startTime.valueOf()).mul(
113+
1_000_000
114+
);
115+
}
116+
117+
if (params.endTime) {
118+
// milliseconds 10^-3 to nanoseconds 10^-9
119+
endTime = Long.fromNumber(params.endTime.valueOf()).mul(1_000_000);
120+
}
116121
return new HistoryRPC(
117122
{
118123
requestId: uuid(),

0 commit comments

Comments
 (0)