Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Calendar events don't correctly overlap

    If multiple calendar event starts at XX:15 or later and end XX:44 or earlier of the same hour, they are not shown overlapped in the day and week view. Instead, one of the events takes the complete space of the row.

    The following example demonstrates the behavior (screenshot of results attached):
    Code:
    Date today = new Date();
    int year = today.getYear();
    int month = today.getMonth();
    int start = today.getDate() - today.getDay();
    
    Calendar calendar = new Calendar();
    calendar.setData(new CalendarEvent[] {
    	new CalendarEvent(1,
    		"Working scenario (later end date) - event 1", "x",
    		new Date(year, month, start, 8, 15, 0), new Date(
    		year, month, start, 8, 45, 0)),
    	new CalendarEvent(2,
    		"Working scenario (later end date) - event 2", "x",
    		new Date(year, month, start, 8, 15, 0), new Date(
    		year, month, start, 8, 45, 0)),
    	new CalendarEvent(3,
    		"Working scenario(earlier start date)  - event 1",
    		"x", new Date(year, month, start, 9, 14, 0),
    		new Date(year, month, start, 9, 44, 0)),
    	new CalendarEvent(4,
    		"Working scenario(earlier start date)  - event 2",
    		"x", new Date(year, month, start, 9, 14, 0),
    		new Date(year, month, start, 9, 44, 0)),
    	new CalendarEvent(5, "Failing scenario - event 1", "x",
    		new Date(year, month, start, 10, 15, 0), new Date(
    		year, month, start, 10, 44, 0)),
    	new CalendarEvent(6, "Failing scenario - event 2", "x",
    		new Date(year, month, start, 10, 15, 0), new Date(
    		year, month, start, 10, 44, 0)) });
    
    calendar.setAutoFetchData(true);
    calendar.draw();
    I saw the issue in SmartGWT 2.2 and could reproduce it as well with SmartGWT trunk version (SVN revision 1449).

    Do I do something wrong or is this a bug?
    Attached Files

    #2
    Please find attached a self-contained test case, which directly runs.
    Attached Files

    Comment


      #3
      I'm by now quite convinced that this is a bug.

      I'm happy to look into this for a fix. Could anybody give me a hint where to look?

      Thanks

      Comment


        #4
        The problem is in ISC_Calendar.js:_prepareAutoArrangeOffsets().

        The hour/minute of the event start and end are calculated by rounding. For an event that lasts from 9:15-9:44 this means that the start as well as the end hour/minute is 9:30. Therefore the startIndex and endIndex are the same and _prepareAutoArrangeOffsets thinks that there are 0 columns.

        The correct calculation is to use floor of the start hour/minute and ceil of the end hour/minute.

        I propose therefore the following change to _prepareAutoArrangeOffsets:
        Code:
                if (startOffset) {
                    // it's not on an exact boundary - round it up or down accordingly
        /* Removed: Start hour should be always the earliest possible time
                    if (startOffset < this.eventSnapGap / 2) {
         */
                        startMinutes = startMinutes - startOffset;
        /* Removed
                    } else {
                        startMinutes = startMinutes + (this.eventSnapGap - startOffset);
                        if (startMinutes == 60) {
                            startMinutes = 0;
                            startHours++;
                        }
                    }
         */
                }
                if (startHours == 24) startHours = 0;
        
                var endHours = curr[this.endDateField].getHours(),
                    endMinutes = curr[this.endDateField].getMinutes(),
                    endOffset = endMinutes % this.eventSnapGap;
                if (endOffset) {
        /* Removed: End hour should be always the latest possible date
                    if (endOffset < this.eventSnapGap / 2) {
                        endMinutes = endMinutes - endOffset;
                    } else {
         */
                        endMinutes = endMinutes + (this.eventSnapGap - endOffset);
                        if (endMinutes == 60) {
                            endMinutes = 0;
                            endHours++;
                        }
        /* Removed
                    }
         */
                }
                if (endHours == 0) endHours = 24;
        I successfully run the folling corner cases:
        Code:
        calendar.setData(new CalendarEvent[] {
        	new CalendarEvent(1, "Event 1 - Problem", "x", new Date(year,
        		month, start, 9, 15, 0), new Date(year, month, start,
        		9, 44, 0)),
        	new CalendarEvent(2, "Event 2 - Problem", "x", new Date(year,
        		month, start, 9, 15, 0), new Date(year, month, start,
        		9, 44, 0)),
        	new CalendarEvent(3, "Event 3", "x", new Date(year, month,
        		start, 8, 14, 0),
        		new Date(year, month, start, 8, 44, 0)),
        	new CalendarEvent(4, "Event 4", "x", new Date(year, month,
        		start, 8, 14, 0),
        		new Date(year, month, start, 8, 44, 0)),
        	new CalendarEvent(5, "Event 5", "x", new Date(year, month,
        		start, 10, 15, 0), new Date(year, month, start, 10, 45,
        		0)),
        	new CalendarEvent(6, "Event 6", "x", new Date(year, month,
        		start, 10, 15, 0), new Date(year, month, start, 10, 45,
        		0)),
        	new CalendarEvent(7, "Event 7", "x", new Date(year, month,
        		start, 11, 10, 0), new Date(year, month, start, 11, 45,
        		0)),
        	new CalendarEvent(8, "Event 8", "x", new Date(year, month,
        		start, 11, 10, 0), new Date(year, month, start, 11, 45,
        		0)),
        	new CalendarEvent(9, "Event 9", "x", new Date(year, month,
        		start, 11, 45, 0), new Date(year, month, start, 12, 0,
        		0)),
        	new CalendarEvent(12, "Event 10", "x", new Date(year, month,
        		start, 11, 45, 0), new Date(year, month, start, 12, 0,
        		0)) });
        I'd apreciate if somehow who knows the code better could double check that there are no hidden side effects of the proposed fix.

        Also: Is there a source code repository from which I can check out the SmartClient code? Then I can attach a proper patch file.

        Thanks a lot!
        rroeller

        Comment


          #5
          Hi RRoeller,
          Thanks very much for tracking this down and putting together this patch code.

          We very much appreciate the contribution.

          We've now integrated this change into our mainline codebase, so the fix will show up in builds going forward.

          Isomorphic Software

          Comment


            #6
            Hello,

            I am using SmartGWT 2.4 plugin in our project. I am also facing this above mentioned issue when we two events scheduled at the same time.
            Please let me know if this issue is already fixed in SmartGWT 2.4 plugin and how do i ensure it?

            Comment

            Working...
            X