[SERVER-56221] $dateAdd ignores startDate milliseconds Created: 21/Apr/21  Updated: 29/Oct/23  Resolved: 14/May/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Percy Assignee: Denis Grebennicov
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query Execution 2021-05-17
Participants:

 Description   

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



 Comments   
Comment by Githook User [ 14/May/21 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-56221 $dateAdd ignores startDate milliseconds
Branch: master
https://github.com/mongodb/mongo/commit/11f57fd3779713de3e2e3b6a2ab3769c3ef95e65

Generated at Thu Feb 08 05:38:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.