Subject: Re: bug#10699: bug of `date`: why 1/1/2012 is the second week of 2012?

From: Eric Blake <[email-masked]>
Date: Thu, 02 Feb 2012 11:42:20 -0700

On 02/02/2012 11:32 AM, Eric Blake wrote:
> The coreutils FAQ at
> https://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e
> has more information, including a link to
> http://en.wikipedia.org/wiki/ISO_8601, which describes where ISO 8601
> week 1 starts:
> 
>> There are mutually equivalent 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.
>>
>> If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.
> 
> That means in ISO 8601 week numbering (%G%V), there is no week 0, days
> falling before week 1 are assigned to the last week of the previous year
> (likewise, days at the end of the calendar year can be assigned into
> week 1 of the next year).  But since week-based years can be confusing
> if you aren't familiar with ISO, POSIX provides not one, but two
> alternatives.  If you like ISO 8601 weeks starting on Monday, then the
> POSIX counterpart (%Y%W) is guaranteed to match the ISO week numbering
> for all days except those at the beginning or end of the calendar that
> ISO would assign into a different year, but where POSIX assigns them to
> week 0 or week 52/53 instead.

Correction - %W can list a different week than %V.  A better way to look
at it is that week 1 in all three systems is the first week that has a
full 7 days assigned to the current year.  Week 0 only exists if there
are days that fall before week 1 but are still assigned to the current
year, and if week 0 exists, it will have less than 7 days.  Week 0 does
not exist for the %V system, which instead shuffles which year things
are assigned to.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org