Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

set time slots with date in javascript

function (cb){

         var duration = 60;
         var freeSlots = [];

         var workingStartTime = 2018-05-12T08:00:00.000Z; 
         var workingEndTime = 2018-05-12T22:00:00.000Z;

         var busySlots = [];
         busySlots.push({ start_time: "2018-05-12T14:30:00.000Z",end_time: "2018-05-12T17:45:00.000Z" }) ;
         busySlots.push({ start_time: "2018-05-12T20:30:00.000Z",end_time: "2018-05-12T21:45:00.000Z" }) ;

         var beginAt = workingStartTime;
         var overAt = workingEndTime;
         var count = 0;
         var last = busySlots.length;

         async.forEach(busySlots, function (item, callback){

             /*** Library funcition to gind difference between two dates (Minutes) ***/
             var diff = libFunc.getRange(beginAt, item.start_time,TIME_UNITS.MINUTES);
             if(diff > duration){
               let free = {"start_time":beginAt , "end_time":item.start_time};
               freeSlots.push(free);
               beginAt = item.end_time;
               count += 1;

               /** Process for end slot **/
               if(last == count){
                 var diff = libFunc.getRange(item.end_time, overAt, TIME_UNITS.MINUTES);
                 if(diff > duration){
                   let free = {"start_time":item.end_time , "end_time":overAt};
                   freeSlots.push(free);
                   callback();
                 }else{
                   callback();
                 }
               }else{
                 callback();
               }
               /** Process for end slot **/

             }else{
               beginAt = item.end_time;
               count += 1;

               /** Process for end slot **/
               if(last == count){
                 var diff = libFunc.getRange(item.end_time, overAt, TIME_UNITS.MINUTES);
                 if(diff > duration){
                   let free = {"start_time":item.end_time , "end_time":overAt};
                   freeSlots.push(free);
                   callback();
                 }else{
                   callback();
                 }
               }else{
                 callback();
               }
               /** Process for end slot **/
             }

         }, function(err) {
           // console.log(freeSlots);
             cb(null);
         });
       },
Comment

PREVIOUS NEXT
Code Example
Javascript :: function hoisting in js 
Javascript :: jquery replace attribute 
Javascript :: javascript recursive on object of arrays 
Javascript :: discord.js reading json object from json 
Javascript :: js findindex 
Javascript :: news api react native 
Javascript :: stop execution javascript 
Javascript :: how to use react fragment 
Javascript :: javascript sort two-dimensional array by column 
Javascript :: jquery find attribute from siblings 
Javascript :: jquery daterangepicker using moment 
Javascript :: what is state in react 
Javascript :: jquery clone object 
Javascript :: impress.js cdn 
Javascript :: how to apply reduce to an empty array in javascript 
Javascript :: javascript split text after x characters 
Javascript :: javascript undefined 
Javascript :: json parse 
Javascript :: jest Cross origin http://localhost forbidden 
Javascript :: how to strip html tags in javascript 
Javascript :: array 
Javascript :: react event for modals 
Javascript :: how to get 6 months after date object 
Javascript :: js run npm 
Javascript :: how to stop overlapping divs to interact with each others click events 
Javascript :: how to connect ms access database in html using javascript 
Javascript :: two dimensional array in javascript 
Javascript :: Animated Sticky Header 
Javascript :: vuejs get data fromo ajax 
Javascript :: react 18 double render 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =