I've been searching on Stack for an answer to my question, but I haven't found a solution yet. My issue is that I need to display only the object in my array where the current time falls within the specified date range defined by timeStart
and timeEnd
. For example, if the current time is 2020-10-22T16:35:45+01:00
, the function should display Steve's appointment. How can I find the object with the current time within the given date ranges?
const currentTime = Date.now(); // 2020-10-22T16:35:45+01:00
Here is the array I'm dealing with:
[
{
name: "Thomas",
timeStart: "2020-10-22T16:00:00+0100",
timeEnd: "2020-10-22T16:15:00+01:00"
},
{
name: "Marc",
timeStart: "2020-10-22T16:15:00+0100",
timeEnd: "2020-10-22T16:30:00+01:00"
},
{
name: "Steve",
timeStart: "2020-10-22T16:30:00+0100",
timeEnd: "2020-10-22T16:45:00+01:00"
}
]