After reviewing the documentation, my understanding was that ISODate simply wrapped the Date constructor. However, I've encountered issues when working with dates very far in the past. For example:
new Date(-8640000000000000); // Mon Apr 19 -271821 18:00:00 GMT-0600 (Mountain Daylight Time)
new Date(-8640000000000000).toISOString(); // -271821-04-20T00:00:00.000Z
ISODate(new Date(-8640000000000000).toISOString()); // Wed Sep 03 2719 18:00:00 GMT-0600 (Mountain Daylight Time)
It's puzzling why the first date and the last date do not match. There seems to be some kind of overflow occurring. Also, what are the limits of dates that MongoDB can handle?
Edit: Interestingly, the following works as expected:
new Date( new Date(-8640000000000000).toISOString()); // Mon Apr 19 -271821 18:00:00 GMT-0600 (Mountain Daylight Time)