-
Type: Question
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
Labels:
> Timestamp.fromNumber(now.valueOf())
new Timestamp({ t: 395, i: -2050878375 })
at
https://github.com/mongodb/js-bson/blob/77fac2a369c9009e88604a9dce0c688778826973/src/timestamp.ts#L104
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
/** Returns a Timestamp represented by the given (32-bit) integer value. */ static fromInt(value: number): Timestamp
What unit of time are the inputs in? Both seconds and milliseconds seem to be accepted:
import { Timestamp } from "mongodb"; const now = new Date(); const timestamp1 = Timestamp.fromNumber(now.getTime() / 1000); const timestamp2 = Timestamp.fromNumber(now.getTime()); console.log(timestamp1.toJSON()); // { '$timestamp': '1698782087' } console.log(timestamp2.toJSON()); // { '$timestamp': '1698782087872' }
That suggests it is seconds but BSON docs state time part of timestamp is stored as seconds since the Unix epoch.
I would like it to be clarified in documentation .