[SERVER-15275] Datetimes before the epoch are exported as $numberLong Created: 16/Sep/14  Updated: 31/Aug/16  Resolved: 16/Sep/14

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.6.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to TOOLS-1422 Mongoimport cannot import dates that ... Closed
is related to DRIVERS-173 Support decoding $date from ISO-8601 ... Closed
Operating System: ALL
Participants:

 Description   

In SERVER-11813 mongoexport was changed to output BSON datetime as a string instead of an integer. Apparently this change was never made for datetimes before the epoch.

From the shell:

repl0:PRIMARY> db.bar.find()
{ "_id" : ObjectId("5418b3d2fba5220c4bff1a1b"), "dt" : ISODate("1969-12-31T16:00:00Z") }
{ "_id" : ObjectId("5418b3f0fba5220c4bff1a1c"), "dt" : ISODate("1970-01-01T00:00:00Z") }

mongoexport:

$ ./mongoexport -d foo -c bar
connected to: 127.0.0.1
{ "_id" : { "$oid" : "5418b3d2fba5220c4bff1a1b" }, "dt" : { "$date" : { "$numberLong" : "-28800000" } } }
{ "_id" : { "$oid" : "5418b3f0fba5220c4bff1a1c" }, "dt" : { "$date" : "1969-12-31T16:00:00.000-0800" } }



 Comments   
Comment by Andy Schwerin [ 16/Sep/14 ]

This is as designed. Date-times before the unix epoch do not have reliable conversions to ISO8601 date strings. The POSIX standard makes no promises that its time formatting functions work before the epoch, and we rely on OS time formatting functions. In practice, different OSes behave differently for pre-epoch time formatting requests.

As an aside, before the early 1960s, there's no true mapping between a count of seconds from a fixed time point and a date and time because there is no reference clock.

The problem gets more complicated if you think about the distant past, say before time zones. MongoDB's Date type isn't really implemented to deal with that, beyond answering "before" and "after" queries.

Generated at Thu Feb 08 03:37:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.