Increase the current time by 50 minutes

I have a dropdown menu with various time options like this:

<select name="" id="delyvery-hour">
  <option value="18:00">18:00</option>
  <option value="18:05">18:05</option>
  <option value="18:15">18:15</option>
  <option value="18:20">18:20</option>
  <option value="18:25">18:25</option>
  ...
  <option value="20:00">20:00</option>
</select>

Using jQuery, I want to display only the options that are 50 minutes ahead of the current time.

For example, if it's currently 18:00, I only want to show options starting from 18:50. Or if it's 19:20, I want to display options from 20:10 onwards.

You can see an example here: https://codepen.io/7lifedesign/pen/dyvaxWW

var dt = new Date();
var time = dt.getHours();
document.write(time);

 $('#delyvery-hour option').filter(function(){
   return parseInt(this.value,10) < time;
 }).remove();

Answer №1

To simplify, just get the current date and time, add 50 minutes to it, and format it in hh:mm form. Then, clean up your <option> elements by removing any option with a value less than the calculated hh:mm.

function pad2(n) {
    if (n < 10) {
      n = '0' + n;
    }
    return n;
}

var dt = new Date();
dt.setMinutes( dt.getMinutes() + 50 ); // Add 50 minutes
var hhmm = pad2(dt.getHours()) + ':' + pad2(dt.getMinutes()); // Example: 18:05

$('#delyvery-hour option').filter(function(){
     return this.value < hhmm;
}).remove();
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>

<select name="" id="delyvery-hour">
  <option value="18:00">18:00</option>
  <option value="18:05">18:05</option>
  <option value="18:15">18:15</option>
  <option value="18:20">18:20</option>
  <option value="18:25">18:25</option>
  <option value="18:30">18:30</option>
  <option value="18:35">18:35</option>
  <option value="18:40">18:40</option>
  <option value="18:45">18:45</option>
  <option value="18:50">18:50</option>
  <option value="18:55">18:55</option>
  <option value="19:00">19:00</option>
  <option value="19:05">19:05</option>
  <option value="19:15">19:15</option>
  <option value="19:20">19:20</option>
  <option value="19:25">19:25</option>
  <option value="19:30">19:30</option>
  <option value="19:35">19:35</option>
  <option value="19:40">19:40</option>
  <option value="19:45">19:45</option>
  <option value="19:50">19:50</option>
  <option value="19:55">19:55</option>
  <option value="20:00">20:00</option>
</select>

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

Save the output of a knex query to a variable

I'm struggling to assign the result of a select query using Knexjs to a variable. Here is my code: function getAllCategories() { let categories; categories = database.from("categories").select("category").then(function (rows) { for (let row of ro ...

When I try to pass a variable as a prop to another .js file, it mysteriously transforms into an undefined value

Upon successful login, my app file sets the isAuthenticated variable to true and redirects to the /admin page. The Firebase API call is functioning as expected, allowing access only with a valid username and password. The issue arises when I try to hide t ...

How can I properly parse a JSON file in Node.js?

Utilizing node.js, I have created a webpage (index.html) for visualizing a network graph using the vis.js library. To draw a network graph with this library, it is necessary to provide json arrays for both nodes and edges (see example). // array of nodes ...

Is the HTTP request from the browser being recorded?

When sending an HTTP request using fetch to website A from the Chrome console on website B, is it possible for website B to track any information about that request, or is it strictly client-side? In other words, can website B detect this action? Thank yo ...

Encountering an issue in my Next.js application with the app router where I am unable to read properties of undefined, specifically in relation to '

As I develop a basic Rest API in Next.js, my goal is to display "Hello world" in the console for a post api. export const POST = (req: Request) => { console.log('hello world'); }; The error message that appears in my terminal is as follows: ...

Guide to transforming an embed/nested FormGroup into FormData

Presenting my Form Group: this.storeGroup = this.fb.group({ _user: [''], name: ['', Validators.compose([Validators.required, Validators.maxLength(60)])], url_name: [''], desc: ['', Validators.compose([Valida ...

Encountering issues with Jest Setup in Next.js as it appears to unexpectedly include a React import in index.test.js

Hey there, I've been pondering over this issue for the past few days. It appears to be a common error with multiple solutions. I'm facing the dreaded: Jest encountered an unexpected token /__tests__/index.test.js:16 import React from "r ...

Removing the empty option in a select element with ng-model

There's a situation I'm dealing with that involves a select dropdown along with a refresh button and a plus button. The issue arises when clicking the refresh button sets the model to null, while clicking the plus button displays the dropdown wit ...

:after pseudo class not functioning properly when included in stylesheet and imported into React

I am currently utilizing style-loader and css-loader for importing stylesheets in a react project: require('../css/gallery/style.css'); Everything in the stylesheet is working smoothly, except for one specific rule: .grid::after { content: ...

I am experiencing an issue where the tooltip does not appear when I click the icon. What adjustments can be made to the code to ensure that the tooltip

I have created a feature to copy abbreviation definitions when the clipboard icon is clicked. A tooltip displaying 'Copied' should appear after clicking the icon, but for some reason, it's not visible. Here's the code: $(document).re ...

Is React failing to identify parameters?

working on my react project, I have an App component which is responsible for rendering multiple child components. Here's how it looks: App render() { return ( //JSX inside <BrowserRouter> <div> <Heade ...

How do three buttons display identical content?

I have three buttons on my website, each with its own unique content that should display in a modal when clicked. However, I am experiencing an issue where regardless of which button I click, the same content from the last button added is displayed in the ...

Ways to display an error notification alongside another message

I have set up a validation directive that requires users to check a box. If the checkbox is left unchecked, an error message will be displayed. However, I am facing an issue where the message overlaps with the checkbox text. https://i.sstatic.net/iTKoo.jp ...

Enhance your dynamic php page with the use of a light box feature

Hey, I have created a PHP page that dynamically reads images from a folder and displays them on a gallery page. However, I am facing some issues - I am unable to link an external CSS file and I have to include all the CSS within the HTML. Additionally, I c ...

The jQuery animation concludes before its anticipated completion

I'm currently facing a small issue with a jQuery animation. The HTML code I have is as follows: <div id="menu"> <a id="menu-about" href="/">About...</a><br /> <a id="menu-ask" href="/">Ask me a question</a> ...

Passing objects to an AngularJS form using UIB TypeAhead without two-way binding

In my current situation, I am encountering an issue with a typeahead feature on a repeating form element that consists of 5 input fields. While everything functions correctly when selecting results and populating the input fields, the model does not get up ...

Issues with navigating sliders

I've encountered a problem with my slider arrows while following a YouTube tutorial. They are supposed to appear next to the picture and testimonial, but instead, they are showing up at the top. This issue wasn't present initially, but after enco ...

AngularJS: Users must click submit button twice for it to function properly

It's puzzling that I have to click the submit button on my form twice before it triggers the save function below. My HTML is written in Pug format. Below is a snippet of my HTML template: <form ng-submit="save()"> <div class="form-group" ...

Is it possible for a hybrid app using Angular 7/1.x to enable Hot Module Replacement (H

Having trouble implementing HMR on a hybrid Angular application using the downgradeModule strategy. I previously sought help from a similar question on Stack Overflow Can an Angular 5/1.x hybrid app support HMR? but didn't find a satisfactory answer. ...

Encountering the 'data is null' error when making a Twitter API request, yet the data is successfully displayed in the browser

I am attempting to show the number of followers for a Twitter account, but when I connect to the API using this code: $.getJSON("https://api.twitter.com/1/users/show.json?screen_name=uswitchTech&include_entities=true", function(data) { console.log ...