set time slots with date in javascript

Solutions on MaxInterview for set time slots with date in javascript by the best coders in the world

showing results for - "set time slots with date in javascript"
Eline
07 Aug 2019
1function (cb){
2
3         var duration = 60;
4         var freeSlots = [];
5
6         var workingStartTime = 2018-05-12T08:00:00.000Z; 
7         var workingEndTime = 2018-05-12T22:00:00.000Z;
8
9         var busySlots = [];
10         busySlots.push({ start_time: "2018-05-12T14:30:00.000Z",end_time: "2018-05-12T17:45:00.000Z" }) ;
11         busySlots.push({ start_time: "2018-05-12T20:30:00.000Z",end_time: "2018-05-12T21:45:00.000Z" }) ;
12
13         var beginAt = workingStartTime;
14         var overAt = workingEndTime;
15         var count = 0;
16         var last = busySlots.length;
17
18         async.forEach(busySlots, function (item, callback){
19
20             /*** Library funcition to gind difference between two dates (Minutes) ***/
21             var diff = libFunc.getRange(beginAt, item.start_time,TIME_UNITS.MINUTES);
22             if(diff > duration){
23               let free = {"start_time":beginAt , "end_time":item.start_time};
24               freeSlots.push(free);
25               beginAt = item.end_time;
26               count += 1;
27
28               /** Process for end slot **/
29               if(last == count){
30                 var diff = libFunc.getRange(item.end_time, overAt, TIME_UNITS.MINUTES);
31                 if(diff > duration){
32                   let free = {"start_time":item.end_time , "end_time":overAt};
33                   freeSlots.push(free);
34                   callback();
35                 }else{
36                   callback();
37                 }
38               }else{
39                 callback();
40               }
41               /** Process for end slot **/
42
43             }else{
44               beginAt = item.end_time;
45               count += 1;
46
47               /** Process for end slot **/
48               if(last == count){
49                 var diff = libFunc.getRange(item.end_time, overAt, TIME_UNITS.MINUTES);
50                 if(diff > duration){
51                   let free = {"start_time":item.end_time , "end_time":overAt};
52                   freeSlots.push(free);
53                   callback();
54                 }else{
55                   callback();
56                 }
57               }else{
58                 callback();
59               }
60               /** Process for end slot **/
61             }
62
63         }, function(err) {
64           // console.log(freeSlots);
65             cb(null);
66         });
67       },