Support for ISO-8601 week number standard

Started by Daniel Hofverberg, December 12, 2008, 05:35:18 AM

Previous topic - Next topic

Daniel Hofverberg

Ever since the first SMF version, it has been a problem with the calendar's week numbers, as it only supports the US standard of calculating week numbers.

To be specific, SMF as far as I can tell uses the week containing January 1st to be week number 1. But most European countries uses the ISO-8601 standard, which means that week number 1 will be the first week where at least four days of the week are in that year.

It's definitely needed with a way to select week standards in SMF, so that both standards will work. It hasn't been a problem for 2008, as it happens to be the same in both standards, but will be a problem for 2009 - in Europe, SMF's week numbers will be one off the entire year.

I believe this has been reported several times earlier, but so far nothing seems to have happened. Is anyone actually working on this, or is there any reasopnably easy way to fix it temporarily in the source code to correctly display ISO-8601 week numbers in the calendar?

Oldiesmann

It's kind of a complicated process from what I can tell.

SMF first calculates the week number for the first day of the month:
'week_num' => (int) strftime('%U', mktime(0, 0, 0, $month, 1, $year)),

The week numbers are then adjusted:

// An adjustment value to apply to all calculated week numbers.
if (!empty($calendarOptions['show_week_num']))
{
// 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 ($calendarOptions['start_day'] === 0)
$nWeekAdjust = $month_info['first_day_of_year'] === 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 = $calendarOptions['start_day'] > $month_info['first_day_of_year'] && $month_info['first_day_of_year'] !== 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 ($month_info['first_day']['day_of_week'] < $calendarOptions['start_day'])
$nWeekAdjust--;
}

Daniel Hofverberg

I agree that it looks complicated. I tried to make sense of that code myself before I posted here, but I didn't manage to.

Daniel Hofverberg

I hate to bump such an old topic, but I would really like to know whether anything has been done about this yet? I'm still using 1.1.11, and there week numbers are still off according to European standard (ISO-8601), as week number 1 in SMF is always considered the week containing January 1st.

Is there any support for "correct" week numbers in SMF 2.0, or is there any reasonably simple way of fixing the issue in the code?

bdzpete

The problem still exists in SMF 2.0.2
Wikipedia has good documentation on ISO weeks.
Europe uses ISO week numbers. They are in all our printed diaries.
An ISO week starts on a Monday (unlike the US standard, which is a Sunday start).

If I allow SMF to default to Sunday as first day of the week, the Calendar for April 2012 shows week numbers that match both ISO and US standards.  However, if I set my week to start on a Monday, the Calendar for April 2012 shows a week number that is 1 higher than ISO.

Your reaction might be "leave Sunday as the first day of the week". Unfortunately most of the events in my calendar are at weekends, and I don't want to display them partly in one week and partly in the next.

Any ideas ?

andershz

#5
I'm not allowed to post attachments here, so I put it in http://www.simplemachines.org/community/index.php?topic=473813.0
I have made a mod to replace the US style week numbering in the calender with the ISO 8601 week numbering standard.
It seems to sort of work, but no guarantees, since this is my first mod.
I'm aware of at least one bug.

Arantor

We spent a long time investigating this, and we concluded that we couldn't get it to behave in a way that didn't look confusing for users, even if it was 'correct'.

Week beginning on Monday is no problem but users were confused with 'show weeks starting on Sunday' (as is common in the US) but with the week numbers being ISO standard, e.g. January 2012 showing Sunday 1st Jan as week 52, even though it is completely correct.

Given that, the whole confusion vs correctness, we actually just removed it. There's not really enough room in the cells in the table anyway. Also, on the weekly view, that now states 'Week beginning Month Day, Year' or whatever would be appropriate in a given language.

While I realise it probably isn't the 'best' option, it's a slightly less worse alternative than confusing users the way it was when I showed it to them.
Holder of controversial views, all of which my own.


Advertisement: