[COMPASS-4570] $date field being saved incorrectly for old dates Created: 12/Jan/21  Updated: 27/Oct/23  Resolved: 13/Jan/21

Status: Closed
Project: Compass
Component/s: Compass
Affects Version/s: 1.24.6
Fix Version/s: No version

Type: Bug Priority: Major - P3
Reporter: Adamo Tonete (Inactive) Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2021-01-13-16-32-25-770.png    
Documentation Changes: Not Needed

 Description   

Problem Description

When inserting data using the $date operator, if the date is bellow a certain threshold there are some divergences in the value recorded.

Steps to Reproduce

Open Atlas

Create a document with date "1400-01-01 00:00:00"

 

{ "valid_date": { "$date": "1400-01-01T00:00:00" }}

 

Compass will save the document with the following values. Please see  the minutes added.

 

{ "_id": { "$oid": "5ffdf6ca652224f556bc2ecf" },
"valid_date": { "$date": "1400-01-01T05:17:32.000Z" } }

 

Expected Results

We expect the results to be a precise minute instead (still respecting the timezone in the test case -5GMT)

Actual Results

It is adding 17 minutes 32 seconds to the date

Additional Notes

mongo shell keep the same date, it might be driver related.



 Comments   
Comment by Massimiliano Marcon [ 13/Jan/21 ]

This is actually the correct behavior (see this conversation about a similar issue for an explanation: https://gitter.im/HowardHinnant/date/archives/2016/08/10).

If you are expecting that date to be stored in UTC, you can add a Z at the end (1400-01-01T00:00:00Z) and the date will be stored as you expect.

Please note that in the mongo shell, if you insert that document it's actually not inserting that field as a date but as a nested object with a $date field in it.

Generated at Wed Feb 07 22:36:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.