no argument (new Date()) will give an object representing the datetime at the point in time the function was called
an integer representing the number of milliseconds elapsed since 1st January 1970 at 00:00:00 (this will be 13 digits) will give a date object representing that datetime
a string in one of the following ISO-compliant forms – Date.parse() - JavaScript | MDN – will give a date object representing that datetime
I didn’t understand your replay (the 3 points you mentioned) can you elaborate please I checked the docs multiple times and I can’t find the problem with what I did in the code ?
In the docs why this format didin’t work const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
I didn’t understand your replay (the 3 points you mentioned) can you elaborate please
The API must accept any of the valid date strings that can be passed to JavaScript’s Date.parse() method.
const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
That’s not technically a valid format, look:
Those are the valid formats. You don’t use Date.parse directly, but the string it accepts as an argument defines what JS will accept as a valid date string.
What you’ve typed there is what JS’ Date will output as a string, but it isn’t valid input.
Having said that, there is the caveat that Date.parse does accept various other date strings, including in the format you’ve typed, but it’s completely implementation-dependent, JS’ Date stuff is really, really horrible. As far as I can see, what it wants you to do is allow the API to accept:
I apologise, I ignored the non-standard date strings when I was skim reading the requirements and docs, as I assumed the requirements meant a standardised date string.
So, anyway, just allow the function that parses the incoming date in your code to handle (eg) "01 Jan 1970 00:00:00 GMT" or "01 Jan 1970" or whatever, just any allowed date string. It just needs to check if the argument sent via the API, when ran through new Date, actually parses to a date.
I think your main issue is that you’ve got a very specific condition in your code that only allows some formats of date instead of just trying to parse the incoming date string and sending an error response if that fails – the input is going to either be a numeric timestamp or it’s going to be something that new Date (and by extension Date.parse, as that’s where the rules around what is or isn’t valid are defined) will parse, and if it’s neither then it’s not valid.