I am facing a challenge where I need to dynamically adjust the path based on specific time conditions.
In this situation, I will be working with two date variables retrieved from an API: CheckInStartDate
and CheckInEndDate
. The current system date and time are also available for reference.
The path adjustment is required under two circumstances:
CheckInStartDate
minus 1 hour from the current time.CheckInEndDate
plus 1 hour to the current time.
This is the existing code snippet:
$scope.checkIn = function() {
var ONE_HOUR = 60 * 60 * 1000; /* in milliseconds */
$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 proceed with check-in");
}
}