Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to divide the time into periods each specific variable in JavaScript

what im trying to do is that i have a branch that got workhours and so there is more than one services this branch give , so if the client press on service that its duration 15 minutes i need to divide the work hours of the branch into queue list of this duration , from open shift till endshift and also delete all the queues that are on breaktime of the branch

i have this variables:

Startshift="09:10" , breaktime = "12:00" , endBreak="12:30" , endShift="13:00" , period each :10min

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i want to define an array of time periods that contain in each cell specific hour according to specific variable i give

myCode:
startTime = 9 , endTime = 13 , selectedServiceDuration = 10 , middleMin = 10

   for(i=startTime; i<endTime; i++) {

        for(j=middleMin ; j<60; j=j+selectedServiceDuration) {

            arr.push({id:Math.random()*56 , hour:i + ":" + (j===0 ? "00" : j)} );
        }
    }

it will return this way

"hour": "9:10",
"hour": "9:20",
"hour": "9:30",
"hour": "9:40",
"hour": "9:50",
"hour": "10:10",
"hour": "10:20",
"hour": "10:30",
"hour": "10:40",
"hour": "10:50",
"hour": "11:10",
"hour": "11:20",
"hour": "11:30",
"hour": "11:40",
"hour": "11:50",
"hour": "12:10",
"hour": "12:20",
"hour": "12:30",
"hour": "12:40",
"hour": "12:50",

so my code missed hour : 10:00 so that mean the rest of the tabe is incorrect

>Solution :

You have start loop from 10 and end to the 60. and then check j with value 60 because your loop is start from 10 it is not going reverse

Here down is modified code:

for(i=startTime; i<endTime; i++) {

        for(j=10; j<=60; j=j+selectedServiceDuration) {

            arr.push({id:Math.random()*56 , hour:(j===60) ? i+1 : i + ":" + (j===60 ? "00" : j)} );
        }
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading