I was working on a JavaScript application where I set the default "starting date" to 1700-01-01 if the user only selects an "ending date" and doesn't select a beginning date. I chose 1700-01-01 because that's the earliest date that can be stored in a Microsoft SQL Server (or at least the default value). I then store this value in local storage and parse it again later. So effectively I execute these three commands at some point:
testDate = new Date(1700, 0, 1, 0, 0, 0, 0)
testDateStr = testDate.toString()
testDateReparsed = new Date(testDateStr)
console.log(testDateReparsed );
However, testDateReparsed ends up being the date: Thu Dec 31 1699 23:59:24!
This same behavior doesn't happen with dates after 1700-01-01, and also happens with dates before 1700-01-01. So if I repeated the same code except the year was 2000 instead of 1700, testDateReparsed would be 2000-01-01 as expected. If the year was 1500 instead of 1700, testDateReparsed would be 1499-12-31 like with the year 1700.
What is the cause of this? Is this a know JavaScript bug or am I missing something?