googling came up with the following function to convert simple week number
to iso week number:
>From the simple week number to the ISO week number.
In [ISO8601], the week number is defined by:
- weeks start on a monday
- week 1 of a given year is the one that includes the first Thursday of
that year. (or, equivalently, week 1 is the week that includes 4 January.)
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;
}
On Wednesday, 10 July 2019 17:40:48 UTC+3, Ferran Vidal Marginet wrote:
>
> Hello,
>
> Today, 10th of July according to my Outlook calendar seems to be week 28
> but the "%W" format in Weewx shows week 27. In general this year this
> format shows one more week than Excel/Outlook/etc.
>
> Somebody knows why? Shouldn't follow ISO8610?
> https://en.wikipedia.org/wiki/ISO_8601
>
> In this thread (
> https://groups.google.com/forum/#!msg/weewx-user/funRVI-T_p0/e58oZtK6AwAJ)
> says that week number follow the following rule:
>
> %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.
>
> and this is not the same as ISO8610. Why? How can I get the same week
> number as ISO8610? The rule that ISO follows is:
>
> There are several mutually equivalent and compatible descriptions of week
> 01:
>
>
> - the week with the year's first Thursday in it (the formal ISO
> definition),
> - the week with 4 January in it,
> - the first week with the majority (four or more) of its days in
> the starting year, and
> - the week starting with the Monday in the period 29 December – 4
> January.
>
> Acording to this today, 10th of July of 2019 is W28.
>
> Thanks,
> Ferran
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/bc8496bf-ec91-4cbd-af68-441c333bf520%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.