Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14623

ObjectId.fromDate is not correct for all dates

    • Fully Compatible
    • ALL
    • Hide

      Run the following code in a v2.7.2/v2.7.3 shell :

      > ok = Math.pow(2, 28)
      268435456
      > notok = ok -1 
      268435455
      > ObjectId.fromDate(new Date(ok  * 1000))
      ObjectId("100000000000000000000000")
      > ObjectId.fromDate(new Date(notok  * 1000))
      Error: invalid object id: length
      Show
      Run the following code in a v2.7.2/v2.7.3 shell : > ok = Math .pow(2, 28) 268435456 > notok = ok -1 268435455 > ObjectId.fromDate( new Date(ok * 1000)) ObjectId( "100000000000000000000000" ) > ObjectId.fromDate( new Date(notok * 1000)) Error: invalid object id: length
    • Server 2.7.4, Server 2.7.5

      The ObjectId.fromDate fails for dates less than (Math.pow(2,28) - 1).

      The code on line 379 should look something like :

          var pad = "00000000";
          var hexSeconds = seconds.toString(16);
          hexSeconds = pad.substring(0, pad.length - hexSeconds.length) + hexSeconds;
      
      

            Assignee:
            jim.oleary@mongodb.com James O'Leary
            Reporter:
            jim.oleary@mongodb.com James O'Leary
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: