Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5725

Clarify the units in bson.Timestamp functions take

    • Type: Icon: Question Question
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
    • 1
    • Not Needed
    • Not Needed

      > 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
      

      at
      https://github.com/mongodb/js-bson/blob/77fac2a369c9009e88604a9dce0c688778826973/src/timestamp.ts#L99

      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 .

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            mhamza@formbird.com Hamza Muhammad
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: