ISODate is used to parse the date from an ISO 8601 string and uses UTC as default time zone if the string does not specify one:
> new ISODate("1977-04-01T00:00:00") ISODate("1977-04-01T00:00:00Z")
> ISODate('2020-09-16T12:41:51.405+0200') ISODate("2020-09-16T10:41:51.405Z")
ISODate also can't parse other formats:
> new ISODate("1/4/1977") 2020-09-16T14:53:59.162+0200 E QUERY [js] uncaught exception: Error: invalid ISO date: 1/4/1977 : ISODate@src/mongo/shell/types.js:79:15 @(shell):1:1
Date instead is working like in other javascript environments, can parse all sort of strings but uses the current timezone instead of UTC if the argument does not specifies one explicitly: > new Date("1977-04-01T00:00:00") ISODate("1977-03-31T23:00:00Z")
In mongosh however it looks like we treat ISODate like the default javascript Date
(notice how the parsing produces an incorrect date as it uses the current timezone):
new ISODate("1977-04-01T00:00:00") 1977-03-31T23:00:00.000Z
NOTE: as part of this ticket it would be good to also align the format of Date and ISODate to be copy/paste friendly, like we do
for the other BSON types:
> new ISODate("1977-04-01T00:00:00") ISODate("1977-04-01T00:00:00Z")
and
> new Date("1977-04-01T00:00:00") ISODate("1977-04-01T00:00:00Z")
- related to
-
MONGOSH-1859 Can ISODate support both the old and new behaviours?
- Closed