0 Replies Latest reply on Jul 16, 2014 11:10 AM by supere

    Calendar code preformance issue

    supere

      I took the below from a function I'm using to render a weekly calendar similar to outlooks weekly calender view. The problem is when I start entering HTML outputs it begins to run very slow. I have another function that returns the events in a structure but if I loop the structure to find events it crashes the browser with a timeout. Can someone tell me what I'm doing wrong, is there a better way??

       

      var local = StructNew();

      //Copy the URL and Form structures into REQUEST

      REQUEST.Attributes = StructCopy(URL);

      StructAppend( REQUEST.Attributes,FORM);

             

      //Define a default opening date

      REQUEST.DefaultDate = Fix(Now());

       

      //START *** time increments

      local.dtTimeIncrement=5;

      local.dtTimeStart=1;

      local.dtTimeEnd=24;

      local.dteventsPerTime=1;

       

      try{

           local.dtThisWeek = (REQUEST.Attributes.date - DayOfWeek( REQUEST.Attributes.date ) +1);

      } catch(any excpt) {

            local.dtThisWeek = (REQUEST.DefaultDate -DayOfWeek( REQUEST.DefaultDate ) +1);

      }

      local.dtPrevWeek = DateAdd( "ww", -1, local.dtThisWeek );

      local.dtNextWeek = DateAdd( "ww", 1, local.dtThisWeek );

      local.dtLastDayOfWeek = (local.dtNextWeek - 1);

      local.dtFirstDay = local.dtThisWeek;

      local.dtLastDay = local.dtLastDayOfWeek;

       

      if ((Year( local.dtThisWeek ) NEQ Year( REQUEST.DefaultDate )) OR (Month( local.dtThisWeek ) NEQ Month( REQUEST.DefaultDate )) OR (Week( local.dtThisWeek ) NEQ Week( REQUEST.DefaultDate ))){

            REQUEST.DefaultDate = Fix( local.dtThisWeek );

      }

       

      //**BEGIN *** Loop the clock HOURS from start time to end time

      for (local.i = local.dtTimeStart; local.i <= local.dtTimeEnd; local.i++) {

           local.DateVal=CreateDateTime(year(REQUEST.DefaultDate), month(REQUEST.DefaultDate), day(REQUEST.DefaultDate), local.i, 00, 00);

       

           //**BEGIN *** LOOP THE WEEK FOR EACH TIME SLOT

           for (local.j = local.dtFirstDay; local.j <= local.dtLastDay; local.j++) {

              local.dtDayTime=CreateDateTime(year(Fix(local.j)),month(Fix(local.j)),day(Fix(local.j)), local.i, 00, 00);

           }

           //**END *** LOOP THE WEEK FOR EACH TIME SLOT

       

           //**BEGIN *** Loop the clock MINUTES from start to end

           for (local.k = 1; local.k <= local.TimeIncSel; local.k++) {

                local.DateVal=CreateDateTime(year(REQUEST.DefaultDate), month(REQUEST.DefaultDate), day(REQUEST.DefaultDate), local.i, local.k*local.dtTimeIncrement, 00);

               

                //**BEGIN *** LOOP THE WEEK FOR EACH TIME SLOT

                 for (local.l = local.dtFirstDay; local.l <= local.dtLastDay; local.l++) {

                      local.dtDayTime=CreateDateTime(year(Fix(local.l)),month(Fix(local.l)),day(Fix(local.l)), local.i, local.k*local.dtTimeIncrement, 00);

                   }

                   //**END *** LOOP THE WEEK FOR EACH TIME SLOT

                }

                //**END *** Loop the clock MINUTES from start to end

      }

      //**END *** Loop the clock HOURS from start time to end time