javascript - Iterating through timeslots -


i'm having little difficulty logic here, it's getting late , honestly, i'm stumped.

i need loop through time slots.

var settings = {     startofweek:0, //0 = sunday, 1 = monday     timeslotgap: 30,     mintime: "09:00:00",     maxtime: "17:30:00",     numslots: 0 }; 

so can specify time slot gap, if iterate through time slots (with 30 minute gap) be:

09:00 09:30 10:00 10:30 

currently have following:

$(document).ready(function () {      getnumslots(settings.mintime, settings.maxtime, settings.timeslotgap);      for(var = 1; i<=settings.numslots; i++){         //i have no idea i'm doing here         $('#calendar').append("<p>timeslot:" + +"</p>");     }   }); var weekno = moment().week(); var currentdate = getcurrentdate(); var weekday = moment().weekday();    var settings = {     startofweek:0, //0 = sunday, 1 = monday     timeslotgap: 60,     mintime: "09:00:00",     maxtime: "17:30:00",     numslots: 0 };   if(settings.startofweek == 0){     weekday = weekday - 1; }   function getnumslots(mintime, maxtime, timeslotgap){     var mintimesplit = mintime.split(":");     var hourstart = new date("01/01/1900 " + mintime).gethours();     var hourend = new date("01/01/1900 " + maxtime).gethours();      var minstart = new date("01/01/1900 " + mintime).getminutes();     var minend = new date("01/01/1900 " + maxtime).getminutes();       var diffhour = hourend - hourstart;     var diffmins = minend - minstart;      var slots = ((diffhour * 60) + diffmins) / timeslotgap;      settings.numslots = slots; } 

if simple looping through 30/60 minutes wouldn't problem since can specify time slot i.e. 90 minutes makes tad difficult.

to time slots use following:

var settings = {     startofweek:0, //0 = sunday, 1 = monday     timeslotgap: 30,     mintime: "09:00:00",     maxtime: "17:30:00",     numslots: 0 };  function gettimedate(time) {     var timeparts = time.split(':');     var d = new date();      d.sethours(timeparts[0]);     d.setminutes(timeparts[1]);     d.setseconds(timeparts[2]);      return d; }  function gettimeslots(startdate, enddate, interval) {     var slots = [];      var intervalmillis = interval * 60 * 1000;      while (startdate < enddate) {         // "00" if we're on hour.         var mins = (startdate.getminutes() + '0').slice(0, 2);         slots.push(startdate.gethours() + ':' + mins);         startdate.settime(startdate.gettime() + intervalmillis);     }      return slots; }  var slots = gettimeslots(     gettimedate(settings.mintime), gettimedate(settings.maxtime), settings.timeslotgap ); 

here's example jsfiddle.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -