scheduler.getEvents=function(E, D) not working as expected

Hi Guys,
I was reviewing the scheduler.getEvents=function(E,D) function in dhtmlxscheduler.js as my collisions were not working as I had expected them too. If I put a breakpoint on
A.push©;
In the following section of code:

scheduler.getEvents=function(E,D)
{
    var A=[];
    for(var B in this._events)
    {
        var C=this._events[B];
        if(C&&C.start_date<D&&C.end_date>E)
        {
            A.push(C);
        }
    }
    return A;
};

My variables are as follows:
C.start_date = Thu Sep 9 00:00:00 UTC+1000 2010
C.end_date = Sat Sep 11 00:00:00 UTC+1000 2010
C.start_date<D = true
C.end_date>E = true
Thu Sep 9 00:00:00 UTC+1000 2010
Wed Sep 8 00:00:00 UTC+1000 2010

I casted the variables as dates, and then the collisions stopped occuring when they were not ment too:

scheduler.getEvents=function(E,D)
{
    var A=[];
    for(var B in this._events)
    {
        var C=this._events[B];
        var c_start_date = new Date(C.start_date);
        var c_end_date = new Date(C.end_date);
        E = new Date(E);
        D = new Date(D);
        if(C&&c_start_date<D&&c_end_date>E)
        {
            A.push(C);
        }
    }
    return A;
};

Too produce this issue, I created 3 events in any section other than the first one, then drag and dropped them too be sequential, and then it would cause the events too collide. Too do this, you must move one too the end, then move the next event before that one (the end date of the first one and the start date of the second one was the condition that was failing). There is another issue which I have noticed now that I have made the code change above. It believes that the two events are running simultaniously and pushes the next sequential event down within the section (below the previous sequential event). I believe this is being caused from variables being compared as a string rather than as a date too, in another section of code.

Hopefully this can be resolved easily and patched into the next release?

Kind regards
Greg Goldberg

P.S. I suspect there may be other places where dates are being compared as a string rather than as a date, due too intermittent behaviour such as the issue described above. Ensuring that date variables are cast as a new date variable will immediately resolve such issues.

Hello,

We couldn’t recreate this issue locally using provided steps.
Can you clarify the problem you are experiencing and steps to reproduce a bit?

Events are not collided in the screenshot below.

Best regards,
Ilya

Hi Ilya,
Thanks for the prompt response, I do have code to change the dates within the scheduler, but I believe this may be related too my regional settings, but I have posted below any code I have related to dates implemented on my scheduler, so that you can have clarity on my use case. In the scenario you show above, I would drag and drop event 2 into another section, then drag and drop it back into that section, and it would collide.

The following code is my regional settings, as I am in Australia, I would prefer to show the date with the following settings (EDIT. The dates in my database are also held in australian format):

scheduler.config.xml_date = "%Y/%m/%d %H:%i";

	scheduler.createTimelineView({
		name:	"timeline",
		render: "bar",
            		section_autoheight: false,
            		dy:   25,
		x_unit:	"day",
		x_date:	"%D %d %M",
		x_step:	  1,
		x_size:   7,
		x_start:  0,
		x_length: 1,
		y_unit:	sections,
		y_property:	"UserId"
	});

I have duplicated the mini_cal.js file and modified it. I have changed the get and set functions as follows:

                    var thisEndDate = H.end_date;

                    thisEndDate.addDays(-1);
                    G(D[0],H.start_date,0);
                    G(D[1],thisEndDate,1);
                    A=function()
                    {
                    };
                    
                    F[0].value=H.start_date.getHours()*60+H.start_date.getMinutes();
                    F[1].value=H.end_date.getHours()*60+H.end_date.getMinutes()
                },
                get_value:function(D,C)
                {
                    var A=D.getElementsByTagName("input");
                    var B=D.getElementsByTagName("select");
                    
                    var start_date = scheduler.date.add(A[0]._date,B[0].value,"minute");
                    var end_date = scheduler.date.add(A[1]._date,B[1].value,"minute");
                    end_date.addDays(1);
                    var dateDiff = end_date - start_date;
                    while(dateDiff <= 0x0)
                    {
                        end_date.addDays(1);
                        dateDiff = end_date - start_date;
                    }
                    
                    C.start_date=start_date;
                    C.end_date=end_date;
                },

And the render function so it does not display the time

                if(B.first_hour)
                {
                    E.setHours(B.first_hour)
                }
                D+=" <select style=\"display: none;\">";

Finally, I have implemented an ASP.NET textbox with a Calendar extender attached to it using the format of 06 October 2010 (Which can also not be misinterpreted by JavaScript when using it in the var thisdate = new Date(’06 October 2010’); syntax) the and it is set to read only. I then have the following functions defined, with the following call to attach an event to the textbox:

function ChangeSchedulerDate()
{
    var schedulerDate = document.getElementById('ctl00_cphMainContent_ucUserScheduler_txtSchedulerDate');
    var schedDate = new Date(schedulerDate.value);
    scheduler.setCurrentView(schedDate);
}
function InitDates()
{
        var txtSchedulerDate = document.getElementById('ctl00_cphMainContent_ucUserScheduler_txtSchedulerDate');
        
        var d = scheduler._date;
        var curr_date = d.getDate();
        var curr_month = d.getMonth();
        var curr_year = d.getFullYear();
        
        var m_names = new Array("January", "February", "March", 
            "April", "May", "June", "July", "August", "September", 
            "October", "November", "December");
           
        var dayString = "";
        if(curr_date < 10)
        {
            dayString = "0" + curr_date;
        }
        else
        {
            dayString = curr_date;
        }
       
        txtSchedulerDate.value = dayString + " " + m_names[curr_month] + " " + curr_year;
}

          scheduler.attachEvent("onViewChange", function (mode , date){
               //change the date in the textbox when the view changes
               InitDates();
          });
        //change the dates on the textbox
        InitDates();
        var txtSchedulerDate = document.getElementById('ctl00_cphMainContent_ucUserScheduler_txtSchedulerDate');
        txtSchedulerDate.attachEvent("onchange", ChangeSchedulerDate);

I have touched on a lot of the date functionality on a visual aspect, but I have always casted it as a date when returning it to the scheduler.

Kind regards
Greg

P.S. The add date function

Date.prototype.addDays = function(days) {
    this.setDate(this.getDate()+days);
} 

We was able to locate the reasons of the issue.
Unfortunately it hard to provide the fixed files, but you can do two next changes in your version of code

a) ext/dhtmlxscheduler_timeline.js
locate

pos.x =  yind/10000000; 

replace with

pos.x = 0;

b) dhtmlxscheduler.js
locate

scheduler._on_mouse_move ... if (!this._drag_pos
replace with

if (!this._drag_pos || pos.custom

Hi Stanislav,
I was unable too implement the fixes you listed above. The closest I could find in dhtmlxscheduler_timeline.js is:

U.fields[O.y_property]=P[O.y_property]=O.y_unit[Q].key;
U.x=Q/10000000;

And I changed it too

U.fields[O.y_property]=P[O.y_property]=O.y_unit[Q].key;
//U.x=Q/10000000;
U.x = 0;

And in dhtmlxscheduler.js, I changed the following lines of code

if(this._drag_mode)
{
    var G=this._mouse_coords(F);
    if(!this._drag_pos||this._drag_pos.x!=G.x||this._drag_pos.y!=G.y)

too the following:

if(this._drag_mode)
{
    var G=this._mouse_coords(F);
    if (!this._drag_pos || pos.custom ||this._drag_pos.x!=G.x||this._drag_pos.y!=G.y)

After I made these changes, The event box could not be dragged, but would still be dropped vertically (and not horizontally).

Kind regards
Greg Goldberg

second one will be

 if (!this._drag_pos || G.custom ||this._drag_pos.x!=G.x||this._drag_pos.y!=G.y)

Hi Stanislav,
Will implement the code and test first thing in the morning.
Kind regards
Greg

Hi Stanislav,
Thanks for this, it worked as expected after your code fix.
Kind regards
Greg

Hi Stanislav,
I have just discovered that the issue is resolved in all cases except one. When I create an event initially using the drag and drop method, and then size the event so that it overlaps with an event that was in an earlier time slot in the same section (in timeline view), the collision script will not take effect.
Kind regards
Greg

Hello,

The issue is confirmed. Fix will be included in the upcoming version and I will post if anything could be done as temporary solution.

Once again - thank you for your feedback.

Best regards,
Ilya

Hi Ilya,
Thanks for your feedback, I am really looking forward to seeing the new version, with all the work you guys are putting into it, it sounds like it is going to be a really great release.
Kind regards
Greg