Current time: 04-23-2014, 08:15 PM Hello There, Guest! (LoginRegister)


[Calendar] Event not shown in month view [R]
06-06-2009, 10:59 AM (This post was last modified: 06-06-2009 04:18 PM by Gionet82.)
Post: #11
RE: [Calendar] Event not shown in month view [R]
Of course I could not try all the possible combinations of variables. I have tested out only those involved in the changes I made. However I feel so sure now because the code is simpler than before. For example take a look at this snippet of code:

Old code:
PHP Code:
    // Start constructing the calendar

    
$weekdays fetch_weekday_structure($calendar['startofweek']);

    
$month_start_weekday gmdate("w"gmmktime(000$month$calendar['startofweek']+1$year));
    
    
// This is if we have days in the previous month to show
    
if($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0)
    {
        
$day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search(($month_start_weekday), $weekdays);
        
$day += $calendar['startofweek']+1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year'];
    }
    else
    {
        
$day $calendar['startofweek']+1;
        
$calendar_month $month;
        
$calendar_year $year;
    } 

My code:
PHP Code:
    // Start constructing the calendar

    
$weekdays fetch_weekday_structure($calendar['startofweek']);

    
$month_start_weekday gmdate("w"gmmktime(000$month1$year));    

    
// This is if we have days in the previous month to show
    
if($month_start_weekday != $weekdays[0])
    {
        
$day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search($month_start_weekday$weekdays) - 1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year'];
    }
    else
    {
        
$day 1;
        
$calendar_month $month;
        
$calendar_year $year;
    } 

In the old code, under certain circumstances, the variable $day reached 32 or 33 causing unpredictable behaviors. This is the main cause of the bug reported in the first post.
Find all posts by this user
06-06-2009, 09:09 PM
Post: #12
RE: [Calendar] Event not shown in month view [R]
(06-06-2009 10:59 AM)Gionet82 Wrote:  Of course I could not try all the possible combinations of variables. I have tested out only those involved in the changes I made. However I feel so sure now because the code is simpler than before. For example take a look at this snippet of code:

Old code:
PHP Code:
    // Start constructing the calendar

    
$weekdays fetch_weekday_structure($calendar['startofweek']);

    
$month_start_weekday gmdate("w"gmmktime(000$month$calendar['startofweek']+1$year));
    
    
// This is if we have days in the previous month to show
    
if($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0)
    {
        
$day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search(($month_start_weekday), $weekdays);
        
$day += $calendar['startofweek']+1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year'];
    }
    else
    {
        
$day $calendar['startofweek']+1;
        
$calendar_month $month;
        
$calendar_year $year;
    } 

My code:
PHP Code:
    // Start constructing the calendar

    
$weekdays fetch_weekday_structure($calendar['startofweek']);

    
$month_start_weekday gmdate("w"gmmktime(000$month1$year));    

    
// This is if we have days in the previous month to show
    
if($month_start_weekday != $weekdays[0])
    {
        
$day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search($month_start_weekday$weekdays) - 1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year'];
    }
    else
    {
        
$day 1;
        
$calendar_month $month;
        
$calendar_year $year;
    } 

In the old code, under certain circumstances, the variable $day reached 32 or 33 causing unpredictable behaviors. This is the main cause of the bug reported in the first post.

Yeah, and you know what you also did? You broke the "Start Of Day" functionality.

That fix is invalid.
Visit this user's website Find all posts by this user
06-07-2009, 07:43 AM
Post: #13
RE: [Calendar] Event not shown in month view [R]
(06-06-2009 09:09 PM)Ryan Gordon Wrote:  [...]
Yeah, and you know what you also did? You broke the "Start Of Day" functionality.

That fix is invalid.

Don't worry "Start Of Day" feature is safe and works pretty good with that fix.
Trust me, these fixes work very well. I'm not the only one who says that:

(06-05-2009 02:34 PM)Tomm M Wrote:  [...]
I've tested out the various fixes and they seem pretty good to me. They all fix the issues mentioned and you've even hit ones not noticed before.
[...]

If there is something that you don't understand in the files that I have posted ask and I'll reply if I can. On the contrary if there is some reason why my contribution is not appreciated tell me and I'll not spend another second of my time here. Dodgy
Find all posts by this user
06-07-2009, 07:53 AM
Post: #14
RE: [Calendar] Event not shown in month view [R]
(06-07-2009 07:43 AM)Gionet82 Wrote:  
(06-06-2009 09:09 PM)Ryan Gordon Wrote:  [...]
Yeah, and you know what you also did? You broke the "Start Of Day" functionality.

That fix is invalid.

Don't worry "Start Of Day" feature is safe and works pretty good with that fix.
Trust me, these fixes work very well. I'm not the only one who says that:

You still do need to take into account the "Start Of Day" within the code.
Visit this user's website Find all posts by this user
06-07-2009, 02:56 PM (This post was last modified: 06-08-2009 06:35 PM by Gionet82.)
Post: #15
RE: [Calendar] Event not shown in month view [R]
(06-07-2009 07:53 AM)Ryan Gordon Wrote:  
(06-07-2009 07:43 AM)Gionet82 Wrote:  
(06-06-2009 09:09 PM)Ryan Gordon Wrote:  [...]
Yeah, and you know what you also did? You broke the "Start Of Day" functionality.

That fix is invalid.

Don't worry "Start Of Day" feature is safe and works pretty good with that fix.
Trust me, these fixes work very well. I'm not the only one who says that:

You still do need to take into account the "Start Of Day" within the code.

First of all, are we speaking of the same thing? With the term "Start Of Day" you mean "Start of Week", is it right? In this case I'm going to explain how my code takes into account also the "Start of week" functionality. Please read this carefully before reply me.

For convenience I quote the snippet of code here:
PHP Code:
// Start constructing the calendar

    
$weekdays fetch_weekday_structure($calendar['startofweek']);

    
$month_start_weekday gmdate("w"gmmktime(000$month1$year));    

    
// This is if we have days in the previous month to show
    
if($month_start_weekday != $weekdays[0])
    {
        
$day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search($month_start_weekday$weekdays) - 1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year'];
    }
    else
    {
        
$day 1;
        
$calendar_month $month;
        
$calendar_year $year;
    } 


The variable $calendar['startofweek'] contains the start day of the week and it comes from the database. It is used to build the array $weekdays trough the function fetch_weekday_structure(). So $weekdays contains an ordered list of weekdays depending on a specified starting day.
Here there is the definition of this function: http://crossreference.mybboard.de/nav.ht....html#l546

Please notice that $calendar['startofweek'] and $weekdays[0] always contain the same value. So when we check if($month_start_weekday != $weekdays[0]) we are comparing the day of the week in which the current month starts and our start day of the week. Indeed you could equivalently write it as:
PHP Code:
if($month_start_weekday != $calendar['startofweek'])
    {... 
Only this (whitout || $calendar['startofweek'] != 0) is enough to understand if there are days of the previous month to show at the beginning of the calendar table.

So if the day of the week in which the month starts(e.g. Monday) and our start day of the week (e.g. ...Monday) match, there are no days of the previous month to show and the starting point is:
PHP Code:
        $day 1;
        
$calendar_month $month;
        
$calendar_year $year
Otherwise if they don't match, the starting point is in the previous month and we have to calculate an offset of days from the end of the month.
PHP Code:
        $day gmdate("t"gmmktime(000$prev_month['month'], 1$prev_month['year']));
        
$day -= array_search($month_start_weekday$weekdays) - 1;
        
$calendar_month $prev_month['month'];
        
$calendar_year $prev_month['year']; 
The offset is:

array_search($month_start_weekday, $weekdays) - 1

that is the position(the index) of $month_start_weekday in our ordered list of weekdays (minus one). With a real calendar in front of you it should be very easy to understand. Notice that is true for any start day of the week, even Sunday or Saturday.
Other additions like $day+=$calendar['startofweek']+1 in the old code may cause an overflow of days (32,33,34...). This is the main cause of the reported bug, as the fetching of the events follows that snippet of code.

I hope that you believe me now. Smile
Find all posts by this user
08-20-2009, 07:32 PM
Post: #16
RE: [Calendar] Event not shown in month view [R]
Corresponding Ticket: http://dev.mybboard.net/issues/413

[Image: logo2.png]
MyBBSource.com: Plugins, Themes and MyCodes
Visit this user's website Find all posts by this user


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication