I am trying to compare the opening hours stored on my server with the current time.
Here are the details:
Start: 09.00 End: 00.30
The goal is to determine if the store is open or closed based on the current time. If the current time falls outside of the given start and end times, the store is considered closed.
However, the code I have been using so far is not functioning correctly. It is giving me the following error message:
TypeError: Cannot read property '3' of undefined
firebase.database().ref("v3/standalonelist/bars").on('value', function(snapshot) {
$timeout(function() {
$scope.content = snapshot.val();
snapshot.forEach(function(childSnapshot) {
$scope.data1 = [childSnapshot.val()];
$scope.locations1 = $scope.data1
$scope.locations1.forEach(function(item) {
$scope.getMinutes = function(str) {
var time = str.split('.');
return time[0] * 60 + time[1] * 1;
}
$scope.getMinutesNow = function() {
var timeNow = new Date();
return timeNow.getHours() * 60 + timeNow.getMinutes();
}
var a = new Date();
var day = a.getDay(); // 3
var now = $scope.getMinutesNow();
console.log(item.opens[day]); // returns 09.00
var start = $scope.getMinutes(item.opens[day]); // 09.00
var end = $scope.getMinutes(item.closes[day]); // 01.20
if (start > end) {
end += $scope.getMinutes('24.00');
}
if ((now > start) && (now < end)) {
$scope.$apply(function() {
$scope.open = true; // Store is open
})
} else {
$scope.open = false; // Store is closed
}
})
})