I am stuck with one condition where I have to change the path based on time.
I will have two date variables, CheckInStartDate
and CheckInEndDate
, which will be coming from API.
Current time is system date time.
Path has to change in two conditions.
CheckInStartDate
minus 1 hour of current timeCheckInEndDate
plus 1 hour of current time.
This is the code I currently have.
$scope.checkIn = function() {
var ONE_HOUR = 60 * 60 * 1000; /* ms */
$scope.checkInStartDate= 01/16/2017 09:06:00 AM;
$scope.checkInEndDate= 01/16/2017 11:06:00 AM;
var checkInStartDate=$scope.checkInStartDate;
var checkInEndDate=$scope.checkInEndDate;
var currentDate = new Date();
var checkinStartDate=new Date(checkInStartDate);
var checkinEndDate = new Date(checkInEndDate);
if ((checkinStartDate.getTime()) > (currentDate.getTime() - ONE_HOUR) ||
(checkinEndDate.getTime()) < (currentDate.getTime() + ONE_HOUR)) {
$location.path('/checkIn')
}
else{
alert("cannot checkin");
}
}