I am trying to find out what venues are opened at present using a filter, the thing works well when the time is in between and after the time is not. Then come late night and everything changes.
I am using Moment JS to compare the time now Hour to the close and open in an object.
The object has this format
value = [ {
"id" : "place_01",
"name" : "Place One",
"location" : "Location One",
"hours" : [
{"day": "Sunday", "day_id": 0,
"hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
{"day": "Monday", "day_id": 1,
"hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
{"day": "Tuesday", "day_id": 2,
"hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
{"day": "Wednesday", "day_id": 3,
"hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
{"day": "Thursday", "day_id": 4,
"hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
{"day": "Friday", "day_id": 5,
"hours": "9:00 AM - 9:00 PM", "open": "9:00 AM", "close": "9:00 PM", "tags": "" },
{"day": "Saturday", "day_id": 6,
"hours": "9:00 AM - 9:00 PM", "open": "9:00 AM", "close": "9:00 PM", "tags": "" }
]
}
]
This is the filter
let f1 = value.filter(item => item.hours.some((hour: { day_id: any; close: string; open: string; }) => hour.day_id == moment().format('d') && hour.open <= moment().format('LT') && hour.close >= moment().format('LT') ));
I wanted the filter to bring back value only when all variables are true.
i.e. If the day ID is # and the close if more than Moment() etc…
When the time is between both everything is great then for a few hours after it works fine, where it won’t bring back any values, then at nigh it starts bring values back, very weird.
How can I get this to only bring back values when the time it between xyz times on xyz day.