I'm trying to do some error handling on an existing system. The backend can't be changed as it runs multiple systems. I'm working on moving the frontend from ASP.NET to React. I've come across a problem where I want to check if an array of objects contains a date, but the date retrieved from the backend comes as a /Date(1379282400000)/.
I've done some searches and can't find something that resembles this. I tried this code:
if (data.some(e => new Date(parseInt(e.Date.substr(6))).toDateString() === this.state.date.toDateString()) {
// Logic
}
e.Date
is the key used in the object for the dates and this.state.date
is a date picked by the user. If I just do:
if (data.some(e => e.Date === "/Date(137982400000)/") {
// Logic
}
as a test, then it works fine. So, it seems to be the converting of the date to the string that breaks the function, but can't understand how to fix it.
It would be nice to fix that it checks the date as doing .getTime()
will not work as it could be the same date, but different times.