TerminatorX
TerminatorX

Reputation: 307

add minutes and print

I need to code the following functionality:

  1. User selects the day/frequency.
  2. System shows list of available times/options.

For example: If the user selects 13th April and frequency 60 minutes the system should show the following options:

If the user selects frequency 30 minutes I should print out: - 8:00 to 8:30 - 8:30 to 9:00 - 9:00 to 9:30 - 9:30 to 10:00 - 10:00 to 10:30 - and so on...

I would need help to come out with a good logic to build a function in order to do that. Inside this function I will check a calendar on a DB to see if the slot is available but I'm having some troubles to think on the best approach here. Do you guys have any good suggestion/example (especially to handle times in jquery)

I appreciate your help!

Upvotes: 0

Views: 49

Answers (1)

Andi489156
Andi489156

Reputation: 115

With the Moment.js library, you can simply add minutes, seconds, ... to a given date.

  1. Parse the start moment from your user input.
  2. In a loop add your frequency to the last start moment to retrieve the next / end moment.
  3. Process your times however you like.

Upvotes: 1

Related Questions