[SERVER-43057] mongo shell ISODate() doesn't throw when months and/or days are out of range Created: 27/Aug/19  Updated: 06/Dec/22  Resolved: 03/Dec/21

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

Type: Bug Priority: Minor - P4
Reporter: Andreu B Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Won't Fix Votes: 0
Labels: move-stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Tooling & Methods
Operating System: ALL
Participants:

 Description   

Actually I'm not sure if that's really a bug, though it does look like one to me.

In the mongo shell:

> ISODate("19990000")

returns ISODate("1998-11-30T00:00:00Z")

That is, 1999-01-01 would be 1 January 1999, then 1999-00-00 is 1 January 1999 minus one month minus one day, so 30 November 1998

> ISODate("12345678")

returns ISODate("1238-10-17T00:00:00Z")

Because by the same reasoning, 1234-56-78 is 1234-01-01 plus 55 months and 77 days, which is 17 October 1238.

The #Wikipedia page on ISO 8601 states that months and days must be between 01 and 12 and between 01 and 31 respectively. I couldn't find a source that states otherwise. If that's true, then "19990000" and "12345678" are both invalid date strings; as such I would expect the ISODate() function to throw an error just like it does for other invalid inputs.

 



 Comments   
Comment by Brooke Miller [ 03/Dec/21 ]

We've deprecated the mongo shell in favor of the new mongosh. Unfortunately, we aren't able to pursue improvements to the deprecated shell except in extreme cases, such as critical security fixes. Please start making use of mongosh and let us know if it works for you in this case.

Comment by Danny Hatcher (Inactive) [ 29/Aug/19 ]

Thanks for your report. We'll look into it.

Generated at Thu Feb 08 05:02:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.