-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.2.0, 4.2.1
-
Component/s: BSON
-
None
-
Environment:Windows, Linux (Docker)
When calling toJson() on a Document containing dates before and after epoch (1970), the result differs. Dates after epoch are represented as a string with an ISO 8601 formatted date, while dates before epoch are represented as the number of milliseconds to epoch.
Expectation is that all dates get represented the same way.
Minimal example:
final String jsonInput = "{" + "_id: '1234'," + "foo: ISODate('1970-01-01T00:00:00.001Z')," + "bar: ISODate('1969-12-31T23:59:59.999Z')," + "baz: ISODate('1900-01-01T00:00:00.000Z')" + "}"; final String expectedOutput = "{" + "\"_id\": \"1234\", " + "\"foo\": {\"$date\": \"1970-01-01T00:00:00.001Z\"}, " + "\"bar\": {\"$date\": \"1969-12-31T23:59:59.999Z\"}, " + "\"baz\": {\"$date\": \"1900-01-01T00:00:00Z\"}, " + "}"; Document doc = Document.parse(jsonInput); String jsonOutput = doc.toJson(); if (!expectedOutput.equalsIgnoreCase(jsonOutput)) { System.out.println(jsonOutput); }; // prints {"_id": "1234", "foo": {"$date": "1970-01-01T00:00:00.001Z"}, "bar": {"$date": {"$numberLong": "-1"}}, "baz": {"$date": {"$numberLong": "-2208988800000"}}}
- is related to
-
DRIVERS-1586 Consider changing relaxed representation of dates before the epoch
- Backlog