Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: PerJ on May 27, 2006, 09:00:50 AM

Title: Calendar week numbering needed to be adjusted
Post by: PerJ on May 27, 2006, 09:00:50 AM
Week numbering in the calendar doesn't follow swedish standard, therefore the actual week number is wrong in my calendar.








I suppose this code in Calendar.php, starting about line #178, should be rewritten, but I can't do it myself and I really do need some help.


// An adjustment value to apply to all calculated week numbers.
if (!empty($modSettings['cal_showweeknum']))
{
// Need to know what day the first of the year was on.
$foy = (int) strftime('%w', mktime(0, 0, 0, 1, 1, $curPage['year']));

// If the first day of the year is a Sunday, then there is no adjustment
// to be made. However, if the first day of the year is not a Sunday, then there is a partial
// week at the start of the year that needs to be accounted for.
if ($nStartDay == 0)
$nWeekAdjust = $foy == 0 ? 0 : 1;
// If we are viewing the weeks, with a starting date other than Sunday, then things get complicated!
// Basically, as PHP is calculating the weeks with a Sunday starting date, we need to take this into account
// and offset the whole year dependant on whether the first day in the year is above or below our starting date.
// Note that we offset by two, as some of this will get undone quite quickly by the statement below.
else
$nWeekAdjust = $nStartDay > $foy && $foy != 0 ? 2 : 1;

// If our week starts on a day greater than the day the month starts on, then our week numbers will be one too high.
// So we need to reduce it by one - all these thoughts of offsets makes my head hurt...
if ($firstDayOfMonth['dayOfWeek'] < $nStartDay)
$nWeekAdjust--;
}
else
$nWeekAdjust = 0;


Title: Re: Calendar week numbering needed to be adjusted
Post by: Hurja on June 19, 2006, 07:16:57 AM
i have this issue i think.  week starts on monday and week numbers are 1 too high. this years first day and first week is marked to be a sunday that is lone day in that week where it should start the next week.

any fix for this?

:)
Title: Re: Calendar week numbering needed to be adjusted
Post by: Webrunner on July 04, 2006, 03:57:14 AM
Up!
This is indeed an issue. :(
Title: Re: Calendar week numbering needed to be adjusted
Post by: Webrunner on July 16, 2006, 07:33:19 AM
Still no response? :(