Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why is Jan. 1st the 52nd week of the year?

25 views
Skip to first unread message

anon...@coward.org

unread,
May 20, 2012, 8:20:16 AM5/20/12
to
I'm struggling with this answer:

$ date --date='2012-01-01 12pm CET' +%V%Z
52CET

I took care to ensure the input and output timezones match.

Janis Papanagnou

unread,
May 20, 2012, 8:38:48 AM5/20/12
to
And asking in the Subject:
> Re: Why is Jan. 1st the 52nd week of the year?

There are various week number definitions. The above conforms
to the ISO standard.

Janis

Luuk

unread,
May 20, 2012, 8:49:33 AM5/20/12
to anon...@coward.org
it week 52 of the year 2011

and this:
date --date='2010-01-01 12pm CET' +%V%Z
gives:
53CET
because the first january in 2010 was in week 53 of 2009

Dr J R Stockton

unread,
May 21, 2012, 3:52:00 PM5/21/12
to
In comp.unix.shell message <jpani0$e4$1...@speranza.aioe.org>, Sun, 20 May
2012 12:20:16, anon...@coward.org posted:
[Subject:] A day cannot be a week.

2012-01-01 is 2011-W52-7 - the seventh day of a Mon-Sun ISO 8601 week.
and the year number of such a week is determined by its Thursday.

Whenever using an ISO week number, remember to use also the correct ISO
8061 year number too. See sig, and never trust week-numbering software
of US origin. Check in particular 2003-12-29 2007-12-31 2019-12-30 &
2101-01-02.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

anon...@coward.org

unread,
May 26, 2012, 6:40:08 AM5/26/12
to
> 2012-01-01 is 2011-W52-7 - the seventh day of a Mon-Sun ISO 8601 week.
> and the year number of such a week is determined by its Thursday.

I appreciate the explanation.

While it's good to have standards, bizarre results like this are not
very useful, and cause for confusion. So I've decided to use this
function:

function cal_wom() {
yr=$1
month=$2
day=$3

week_no=`cal $2 $1 | sed -n "3,$ p" | sed -n "/$3/{=;q;}"`
echo $week_no
}

I don't have much choice anyway.. the API I'm calling seems to be
taking day 1 of a year to be the start of the first week of the year,
which is intuitive.

Luuk

unread,
May 26, 2012, 8:12:14 AM5/26/12
to
so, we live in week 4 now....

cal 5 2012 | sed -n "3,$ p" | sed -n "/26/{=;q;}"

anon...@coward.org

unread,
May 26, 2012, 8:42:37 AM5/26/12
to
On 2012-05-26, Luuk <lu...@invalid.lan> wrote:
>
> so, we live in week 4 now....
>
> cal 5 2012 | sed -n "3,$ p" | sed -n "/26/{=;q;}"

Ultimately I needed to compute the week of month (something that is
not available from the standard "date" package). I was considering
using the week of year function of the date package as an input for
that, before discovering the unexpected result it gives.

Luuk

unread,
May 26, 2012, 9:05:53 AM5/26/12
to
~/tmp> function cal_wom { echo "`date -d "$3/$2/$1" +%j` /7 +1" | bc; }
~/tmp> cal_wom 1 1 2012
1
~/tmp> cal_wom 26 5 2012
22

Chris F.A. Johnson

unread,
May 26, 2012, 2:37:54 PM5/26/12
to
week_of_month=$(( $(date +%d) / 7 + 1 ))

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

Ben Finney

unread,
May 26, 2012, 7:27:52 PM5/26/12
to
anon...@coward.org writes:

> > 2012-01-01 is 2011-W52-7 - the seventh day of a Mon-Sun ISO 8601 week.
> > and the year number of such a week is determined by its Thursday.
>
> I appreciate the explanation.
>
> While it's good to have standards, bizarre results like this are not
> very useful, and cause for confusion.

That's a function of our calendar. It's a big hairy ball of compromises
between our bizarre intuitions and conventions and the bizarre real
world, so there will always be confusion in some cases.

> I don't have much choice anyway.. the API I'm calling seems to be
> taking day 1 of a year to be the start of the first week of the year,
> which is intuitive.

So you'll get weeks with fewer than seven days, which seems bizarre and
cause for confusion.

And you'll get weeks starting on different days of the week depending on
which date you ask about, which seems bizarre and cause for confusion.

Rather than making up your own, you might want to investigate whether
the API is using a different standard for week numbering
<URL:https://en.wikipedia.org/wiki/Seven-day_week#Week_numbering>.

--
\ “When we call others dogmatic, what we really object to is |
`\ their holding dogmas that are different from our own.” —Charles |
_o__) Issawi |
Ben Finney

Kaz Kylheku

unread,
May 26, 2012, 11:13:26 PM5/26/12
to
Note that 365 and 366 are not divisible by 7. There are not exactly 52 weeks in a year,
because 52 * 7 is only 364.

Therefore, the last week of a year extends into next year.

If a week must be assigned to a year, and it straddles two years, you have to
make a call: does it go into that year, or the next.

Luuk

unread,
May 27, 2012, 3:49:25 PM5/27/12
to
On 26-05-2012 20:37, Chris F.A. Johnson wrote:
> On 2012-05-26, anon...@coward.org wrote:
>> On 2012-05-26, Luuk <lu...@invalid.lan> wrote:
>>>
>>> so, we live in week 4 now....
>>>
>>> cal 5 2012 | sed -n "3,$ p" | sed -n "/26/{=;q;}"
>>
>> Ultimately I needed to compute the week of month (something that is
>> not available from the standard "date" package). I was considering
>> using the week of year function of the date package as an input for
>> that, before discovering the unexpected result it gives.
>
> week_of_month=$(( $(date +%d) / 7 + 1 ))
>

jmmmmm, i see i still need to read the _complete_ manual ..... ;)

Dr J R Stockton

unread,
May 28, 2012, 2:15:47 PM5/28/12
to
In comp.unix.shell message <87like5...@benfinney.id.au>, Sun, 27 May
2012 09:27:52, Ben Finney <ben+...@benfinney.id.au> posted:

>
>Rather than making up your own, you might want to investigate whether
>the API is using a different standard for week numbering
><URL:https://en.wikipedia.org/wiki/Seven-day_week#Week_numbering>.

You also need to investigate whether the API actually gets it right :
<http://www.merlyn.demon.co.uk/vb-date2.htm#DP>. That's for VBScript
DatePart; but the code is in a DLL, and the indicated bugs appear
wherever they can.
0 new messages