News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Calendar week numbering needed to be adjusted

Started by PerJ, May 27, 2006, 09:00:50 AM

Previous topic - Next topic

PerJ

Week numbering in the calendar doesn't follow swedish standard, therefore the actual week number is wrong in my calendar.




  • A week starts on a monday.

  • January 01 is in week #1 IF it's on a monday, tuesday, wednesday or thursday ELSE it's in week #53.
    This can also be stated as: Week #1 must contain at least 4 of januarys first days.





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;



Hurja

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?

:)

Webrunner

There is a difference between knowing the path and walking the path.

=========================================
Vrouwen Power! | Sprintweb: No nonsense e-Business consultancy

Webrunner

There is a difference between knowing the path and walking the path.

=========================================
Vrouwen Power! | Sprintweb: No nonsense e-Business consultancy

Advertisement: