[mrtg] Re: Week numbering incorrect

Peter Glanville peter_glanville at cuk.canon.co.uk
Thu Jul 24 10:50:19 MEST 2003



> Second, my question. I've noticed that the week numbering in the monthly
> graphs is incorrect. The number is minus 1. It seems that the month
counter
> starts at 0 instead of 1.
> I've tried using Weekformat[_]: V and U, but this doesn't seem to effect
the
> graphs in any way.


I was going to give a sarcstic 'search the archive' answer, only to find
that I cannot find the entry in the archive either!

Luckily I kept a copy:


From: Jerry Heidtke
Date: 9 Jan 2003
Subject: [mrtg] Re: week numbering

More than anyone ever wanted to know about week nummbers...

The "00" being displayed as a week number is correct according to the
"default" ANSI C language specifications. The first day of Week 01 in 2003
is January 6. January 1-5 fall in Week 00.

strftime has three parameters to determine how week numbers are expressed:
%U is replaced by the week number of the year (Sunday as the first day of
the week) as a decimal number [00,53].
%V is replaced by the week number of the year (Monday as the first day of
the week) as a decimal number [01,53]. If the week containing 1 January has
four or more days in the new year, then it is considered week 1. Otherwise,
it is the last week of the previous year, and the next week is week 1.
%W is replaced by the 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.

The WeekFormat option in mrtg simply passes the preferred strftime week
format to rateup.

Note that %W reported week 01 for Jan. 1, 2001, since it was the first
Monday of the year. There was no week 00 according to %W in 2001, and some
people thought that there were problems in their applications when the year
started right off in week 01. In 2002 and 2003, of course, this is not the
case and so other people think something is broken when they see a week 00.

If you don't want to ever see "00" for a week, you could rewrite the
program
and set your own (non-)standard. Or you could use the ISO standard (%V).

According to ISO standards (ISO 8601:1988(E)):

The week in the ISO calendar is defined (sect. 3.27-28 on p. 4) as:
[a] time-interval of seven days, starting on a Monday and identified by its
ordinal number within a calendar year.

The numbering of the ISO calendar weeks is defined (sect. 4.3.2.2 on pp.
7-8) as:
[...] the first calendar week of a year is the one that includes the first
Thursday of that year and [...] the last calendar week of a calendar year
is
the week immediately preceding the first calendar week of the next year.

Note 4 to this section also mentions: The rule for determining the first
calendar week is equivalent with the rule "the first calendar week is the
week which includes January 4".

Therefore, according to ISO, week 01 of 2003 is from Dec. 30, 2002 to Jan.
5, 2003. There can never be a week 00 according to the standard. There can
be either 52 or 53 weeks in a year.

The ISO rules lead to some "unexpected" date specifications. For example,
one of the supported date formats is 2003-W01-1 (that is "Year 2003, Week
01, Day 1"). This actually refers to Dec. 30, 2002.

%V is defined in POSIX, but not in older versions (pre-C99) of ANSI C. %V
doesn't work on Windows in any case, any language (except maybe something
written with Metrowerks), any version. After all, we can't expect Redmond
to
implement international standards in only ten or fiftenn years. Other
common
options for strftime that don't work in at least some versions of Windows
are %G, %h, %e, %n, %U, %T, %R and %D.

I tried the following versions of Perl on Windows:
v5.6.1 built for MSWin32-x86-multi-thread from ActiveState
v5.8.0 built for MSWin32-x86-multi-thread from ActiveState
v5.6.1 built for cygwin-multi
v5.8.0 built for cygwin-multi-64int

This can be tested with the following commands:
perl -e 'use POSIX;' -e 'print strftime("%U",0,0,0,1,0,103);' (returns
'00')
perl -e 'use POSIX;' -e 'print strftime("%V",0,0,0,1,0,103);' (returns '  '
on 5.61, '%V' on 5.80)
perl -e 'use POSIX;' -e 'print strftime("%W",0,0,0,1,0,103);' (returns
'00')

PHP4 on Windows works the same as perl 5.61.

Years after Y2K, some programmers are still putting date bugs in their
programs because they don't know a) how the calendar works, and b) how
their
programming languages work. But mrtg, rateup, and rrdtool are working
correctly.

-----Original Message-----
From: Peter Glanville [mailto:peter_glanville at cuk.canon.co.uk]
Sent: Thursday, January 09, 2003 11:04 AM
To: Koelstra, J. (Jan); mrtg at list.ee.ethz.ch
Subject: [mrtg] Re: week numbering

Read http://www.ee.ethz.ch/~slist/mrtg/msg16311.html
(same topic, same time, last year)

Answer from Tobi was roughly: Week1 starts with the first Monday in
January. Anything before that is not week 1.

I suppose that just leaves the question of whether a week containing Dec31
and Jan1in the middle of it should be labelled week0 or week52!

I tried Weekformat[_]: V and the week numbers vanished for me, too.
I tried %V and the numbers re-appeared (Oops, typo in the reference
manual?). Same week numbers, but the week now starts on a Sunday instead of
Monday.

For the Weekformat command, it's all down to the support from your OS.
(Windoze? - enough said)

Regards
Peter

---------





--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list