%W | Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. |
There are several mutually equivalent and compatible descriptions of week 01:
In [ISO8601], the week number is defined by:
This means that the days before week 1 in a given year are attributed to the last week of the previous year. Also the days that come after the last week of a given year are attributed to the first week of the next year.
If we adapt approximation SWN5 for the simple week number to reflect the differences between the definitions of both week numbers, we arrive at the final solution, adopted for the week number wristapp:
ISO_WN( y, m, d )
{
dow = DOW( y, m, d );
dow0101 = DOW( y, 1, 1 );
if ( m == 1 && 3 < dow0101 < 7 - (d-1) )
{
// days before week 1 of the current year have the same week number as
// the last day of the last week of the previous year
dow = dow0101 - 1;
dow0101 = DOW( y-1, 1, 1 );
m = 12;
d = 31;
}
else if ( m == 12 && 30 - (d-1) < DOW( y+1, 1, 1 ) < 4 )
{
// days after the last week of the current year have the same week number as
// the first day of the next year, (i.e. 1)
return 1;
}
return ( DOW( y, 1, 1 ) < 4 ) + 4 * (m-1) + ( 2 * (m-1) + (d-1) + dow0101 - dow + 6 ) * 36 / 256;
}--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/97d6b0f5-d717-4e51-8620-82b31c86c4c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Many thanks Thomas!
Ferran