On Thu, 6 Aug 2020, Sven Schreiber wrote:
Am 06.08.2020 um 13:36 schrieb Artur Tarassow:
>
> I've found a rather strange 'result' when using the isoweek() function.
For
> some reason the last 2 days of calendar year 2019 do not refer to week 53
> but week 52 instead. For 2020, however, things are alright. Do I miss
> anything or is this a kind of bug?
Actually your output below shows that you get week 1 for the last two days in
2019, not 52...
> <output>
> year month day week
>
> 1 2019 12 29 52
> 2 2019 12 30 1 # WEIRD
> 3 2019 12 31 1 # WEIRD
> 4 2020 12 29 53
> 5 2020 12 30 53
> 6 2020 12 31 53
> </output>
Hm, according to the doc week 1 should refer to the one of "the first Tuesday
of the year". That would be the weeks containing 2019-1-1 and 2020-1-7.
Indeed the "WEIRD" results (which I'm also getting) do not seem to match
the
doc. This also applies to isoweek(2020,1,1)
But in addition this means that your results for 2020-12-29 through
2020-12-31 are also wrong, it should be week 52 instead.
I have only checked against the gretl doc internally, not whether the ISO
norm is accurately described there (which I don't know).
Too much guesswork and inaccurate transcription here! Please read
https://en.wikipedia.org/wiki/ISO_week_date
Sven is right in saying Artur misreports the ISO week of the last
two days of 2019: it's not week 52 of 2019 but week 1 of "ISO
week-numbering year" (or "ISO year" for short) 2020.
However, according to the doc for isoweek() the definition of week 1
is "the week containing the year's first Thursday on the Gregorian
calendar" (not Tuesday). The first Thursday of 2020 occurred on
January 2, which means that the Monday and Tuesday of that week
belong to ISO year 2020, as correctly shown by gretl.
Only about 71/400 ISO years have a week 53; 2019 is not one of them
but 2020 is.
<hansl>
function scalar weeks_in_year (int yr)
long = 0
py = (yr + floor(yr/4) - floor(yr/100) + floor(yr/400)) % 7
if py == 4
long = 1
else
y1 = yr - 1
py1 = (y1 + floor(y1/4) - floor(y1/100) + floor(y1/400)) % 7
if py1 == 3
long = 1
endif
endif
return 52 + long
end function
eval weeks_in_year(2019)
eval weeks_in_year(2020)
</hansl>
Allin