GNU bug report logs -
#10699
bug of `date`: why 1/1/2012 is the second week of 2012?
Previous Next
Reported by: "Wang, YuanTao" <ytwang <at> freewheel.tv>
Date: Thu, 2 Feb 2012 17:06:02 UTC
Severity: normal
Tags: notabug
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
Message #13 received at 10699-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
tag 10699 notabug
thanks
On 02/02/2012 01:25 AM, Wang, YuanTao wrote:
> $ date -d "2012-01-01 00:00:00" +%U
> 01
>
> but in "man date"
> %U week number of year, with Sunday as first day of week (00..53)
>
> Is it a bug?
No, it is behavior required by POSIX,
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html.
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. And if you like weeks starting on Sunday
instead of Monday, then the POSIX counterpart (%Y%U) shifts things to
start week 1 on Sunday instead of Monday, again with week 0 and week 53
rather than rolling things into different years.
--
Eric Blake eblake <at> redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 13 years and 171 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.