the present time plus a one-hour situation

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:

  1. CheckInStartDate minus 1 hour from the current time.
  2. 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");
    }
}

Answer №1

If I understand your query correctly, you are looking to enable check-ins during a specific time frame that falls between the following two times:

  • Check-in Start Date minus 60 minutes
  • Check-in End Date plus 60 minutes

Let's label the first point as A and the second point as B. The current time is C. Your condition should be met when

A < C < B

In JavaScript terms, this can be expressed as:

var A = new Date($scope.checkInStartDate).getTime() - 3600000;
var B = new Date($scope.checkInEndDate).getTime() + 3600000;
var C = new Date().getTime();
if (A < C && C < B) {
    // Allow check-in
} else {
    // Deny check-in
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Differences in performance between Angular and JQuery_execution times

I am facing an issue on my dynamically populated Angular page. Angular sends a request to the backend using $http.get to retrieve data which then populates attributes of a controller. For example, when I call $http.get('/_car_data'), the JSON re ...

Issues with the POST API functionality in an express / node.js application when using mysql database

Recently, I have been diving into learning nodejs and experimenting with creating a post API that interacts with static data stored in a MySQL database. Let me briefly share the configuration setup I am working on: const mysql = require('mysql') ...

Leveraging the power of AJAX with either jquery or plain javascript to parse nested JSON data and display the

Similar Question: jquery reading nested json I am seeking a reliable method to iterate through multiple sets of data stored in JSON, some of which may have deep levels of nesting. My goal is to display this data in a table format. I am uncertain abou ...

Methods for dynamically populating dropdown lists with JavaScript and Bootstrap

I have collected all 387 regions for the current date and now I want to dynamically populate a bootstrap dropdown with these regions using JavaScript. Below is the basic HTML code for a bootstrap dropdown: <div class="dropdown"> <button class ...

Vue Pinia ensures that reactive state is only updated once, preventing unnecessary updates

In my Vue application, the structure is as follows: App.vue -GroupWrapper --GroupListing -PeopleWrapper --PeopleListing -ConversationWrapper Within my user store that utilizes Pinia, I primarily call user.findChats() in the App.vue component. Code snippe ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

The useEffect hook is able to fetch data even when the state stored in the dependency array remains constant

I have been working on developing a quiz page that utilizes the useEffect hook to fetch data. The data retrieved includes the question as well as multiple-choice options. There is a button labeled Check Answer which, when clicked, reveals the user's f ...

Ensuring data integrity with form validation using Jquery prior to submitting an

After researching various forums and referencing one, I am still unable to find a solution for my issue. My query is: When I click a button, it triggers a function that includes validation. Upon successful validation, I attempt to post data with an Aj ...

How can we efficiently execute text searches on a large scale by utilizing static index files that are easily accessible online

Looking for a lightweight, yet scalable solution for implementing a full text search index in JavaScript using static files accessible via HTTP? Seeking to make about 100k documents searchable online without breaking the bank on hosting costs like Elastics ...

Ensure that the alert for an Ajax JSON record count remains active when the count is

Trying out Ajax JSON for the first time has been a bit tricky. Even though I hard coded "Record: 1" on the server side, it keeps alerting me with a total record of 0. I'm not sure where I went wrong. Could it be an issue with how I passed the array da ...

The try/catch block fails to execute or capture any errors

I'm attempting to create a help command that notifies users in case of closed DMs, but it's not working as expected. Despite encountering an error, the original messages are still sent instead of executing the catch function. I am relatively new ...

AngularJS: Working with Authentication Headers for HTTP Requests

I am currently working on an angular application that communicates with a node API. The backend developer has set up basic authentication for the API, and I need to include an auth header in my request. After some investigation, I found this code snippet: ...

The type 'true | CallableFunction' does not have any callable constituents

The error message in full: This expression is not callable. No constituent of type 'true | CallableFunction' is callable Here is the portion of code causing the error: public static base( text, callB: boolean | CallableFunction = false ...

Encountering an undefined variable in the .env file

Once the .env file was created in the main React folder REACT_APP_API_KEY=gzomlK5CKLiaIWS.... I also installed the .env NPM library Despite this, I continued to receive undefined in the API file. What could be causing this issue? import React, { useState ...

Create HTML elements based on the information in a JSON object

My goal is to create span elements for each word in my subtitle text, which is stored in a JSON object. Here is the JSON data I am working with: var sub_info = [ {'start': 3.92, 'end': 6.84, 'words ...

How to dismiss a jQueryMobile dialog without triggering a page refresh

I've encountered a question similar to this before, but there wasn't any solution provided. The issue I'm facing is that I have a form and when a user clicks on a checkbox, I want to open a popup/dialog for them to enter some data. However, ...

Building a single page application architecture with Express and AngularJS

Greetings, I am a novice in the world of nodejs and angularjs. I have a need for an angularjs application and I am considering using expressjs for creating the back-end REST API's. My application consists of two main parts: a front-end UI for genera ...

Tips for seamlessly incorporating WalletConnect into your decentralized app with the help of web3-react

I have been working on integrating WalletConnect into my project by referring to the documentation provided by web3-react. The configuration settings I am using for the connector are as follows: import { WalletConnectConnector } from '@web3-react/wal ...

What is the method to implement foreach within a Vue select component?

Is there a way to utilize a Vue loop within a select box in order to achieve the following category and subcategory options layout: +news -sport -international +blog In PHP, I can accomplish this like so: @foreach($categories as $cat ...

Angular Autocomplete directive - retrieve the list of matching items

I am looking to display the first element suggested by the Angular Typeahead directly in the input box, instead of just in the dropdown. I have searched extensively but have not been able to find a way to access the elements shown in the dropdown. The goal ...