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

$dateAdd ignores startDate milliseconds

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • Query Execution 2021-05-17

      Example expression:

      {$dateAdd: {
        startDate: ISODate("2021-01-01T00:00:00.002Z"),
        amount: 3,
        unit: 'millisecond',
      }}
      

      The startDate is 2 milliseconds after midnight, so I'd expect the result to be 5 milliseconds after midnight. Instead it's 3 milliseconds after midnight: the startDate's milliseconds are truncated before doing the addition.

      It looks like we are truncating here because a timelib helper doesn't accept milliseconds: https://github.com/mongodb/mongo/blob/1eadaf115d098198845026aef15b0f24578b46b8/src/mongo/db/query/datetime/date_time_support.cpp#L1136

      But the timelib struct does have a microseconds field we can populate: https://github.com/mongodb/mongo/blob/1eadaf115d098198845026aef15b0f24578b46b8/src/third_party/timelib-2021.04/timelib.h#L248

            Assignee:
            denis.grebennicov@mongodb.com Denis Grebennicov
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: