GNU bug report logs -
#13372
bug in date with last week calculation
Previous Next
Reported by: Tomas Dabašinskas <tomas <at> redhat.com>
Date: Mon, 7 Jan 2013 00:50:01 UTC
Severity: normal
Tags: notabug
Done: Pádraig Brady <P <at> draigBrady.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13372 in the body.
You can then email your comments to 13372 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 00:50:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Tomas Dabašinskas <tomas <at> redhat.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Mon, 07 Jan 2013 00:50:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
I'm getting week number 53 when trying to get last week on Mon Jan 7 09:46:19 EST 2013:
$ date
Mon Jan 7 09:46:19 EST 2013
$ date -d'last week' +%W
53
Expecting to get week 1
Many thanks!
--
Tomas Dabašinskas | Engineering Content Services | Red Hat Asia Pacific
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 02:01:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 13372 <at> debbugs.gnu.org (full text, mbox):
On 01/06/2013 03:48 PM, Tomas Dabašinskas wrote:
> $ date
> Mon Jan 7 09:46:19 EST 2013
Something odd with your time zone setting?
As I write this, the current time is
Sun Jan 6 20:59:42 EST 2013.
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 02:19:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 13372 <at> debbugs.gnu.org (full text, mbox):
----- Original Message -----
> Something odd with your time zone setting?
> As I write this, the current time is
> Sun Jan 6 20:59:42 EST 2013.
>
Paul,
Many thanks for getting back.
The time zone I'm using is GMT+10 (Australian East Std time).
I'm sorry, I should have clarified this in my bug report, I don't think it's timezone related tough...
Regards,
--
Tomas Dabašinskas | Engineering Content Services | Red Hat Asia Pacific
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 02:43:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 13372 <at> debbugs.gnu.org (full text, mbox):
On 01/06/2013 06:18 PM, Tomas Dabašinskas wrote:
> The time zone I'm using is GMT+10 (Australian East Std time).
Ah, in that case week 53 is correct, no?
$ export TZ=Australia/Sydney; date; date -d'last week'; date -d'last week' +%W
Mon Jan 7 13:41:02 EST 2013
Mon Dec 31 13:41:02 EST 2012
53
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 02:47:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 13372 <at> debbugs.gnu.org (full text, mbox):
----- Original Message -----
> Ah, in that case week 53 is correct, no?
>
> $ export TZ=Australia/Sydney; date; date -d'last week'; date -d'last
> week' +%W
> Mon Jan 7 13:41:02 EST 2013
> Mon Dec 31 13:41:02 EST 2012
> 53
>
>
Paul, I'm using coreutils v8.4 so I think that could be my problem...
--
Tomas Dabašinskas | Engineering Content Services | Red Hat Asia Pacific
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 06:58:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 13372 <at> debbugs.gnu.org (full text, mbox):
Tomas Dabašinskas wrote:
> I'm getting week number 53 when trying to get last week on
> Mon Jan 7 09:46:19 EST 2013:
>
> $ date
> Mon Jan 7 09:46:19 EST 2013
> $ date -d'last week' +%W
> 53
>
> Expecting to get week 1
You are using %W which is described as:
`%W'
week number of year, with Monday as first day of week
(`00'...`53'). Days in a new year preceding the first Monday are
in week zero.
And so:
December 2012
Mo Tu We Th Fr Sa Su
24 25 26 27 28 29 30 <-- week 52
31 <-- week 53
January 2013
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 <-- week 0
7 8 9 10 11 12 13 <-- week 1
14 15 16 17 18 19 20 <-- week 2
21 22 23 24 25 26 27
28 29 30 31
Since you are reporting your current time as Jan 7 then Dec 31 would
be last week. Dec 31 would be week 53.
$ env TZ=Australia/Sydney date -d 'last week' -R
Mon, 31 Dec 2012 16:59:04 +1100
And so:
$ env TZ=Australia/Sydney date -d 'last week' +%W
53
$ env TZ=Australia/Sydney date -d 'Dec 31 2012 12:00 +0000' +%W
53
There are multiple different definitions for week numbers depending
upon weeks starting on Sunday, starting on Monday, and so forth.
Also related are:
`%U'
week number of year, with Sunday as the first day of the week
(`00'...`53'). Days in a new year preceding the first Sunday are
in week zero.
`%V'
ISO week number, that is, the week number of year, with Monday as
the first day of the week (`01'...`53'). If the week containing
January 1 has four or more days in the new year, then it is
considered week 1; otherwise, it is week 53 of the previous year,
and the next week is week 1. (See the ISO 8601 standard.)
You might want to look at the strftime man page for an alternate
description:
man 3 strftime
%U The week number of the current year as a decimal number, range
00 to 53, starting with the first Sunday as the first day of
week 01. See also %V and %W.
%V The ISO 8601 week number (see NOTES) of the current year as a
decimal number, range 01 to 53, where week 1 is the first week
that has at least 4 days in the new year. See also %U and %W.
(SU)
%W The week number of the current year as a decimal number, range
00 to 53, starting with the first Monday as the first day of
week 01.
ISO 8601 Week Dates
%G, %g, and %V yield values calculated from the week-based year defined
by the ISO 8601 standard. In this system, weeks start on a Monday, and
are numbered from 01, for the first week, up to 52 or 53, for the last
week. Week 1 is the first week where four or more days fall within the
new year (or, synonymously, week 01 is: the first week of the year that
contains a Thursday; or, the week that has 4 January in it). When
three of fewer days of the first calendar week of the new year fall
within that year, then the ISO 8601 week-based system counts those days
as part of week 53 of the preceding year. For example, 1 January 2010
is a Friday, meaning that just three days of that calendar week fall in
2010. Thus, the ISO 8601 week-based system considers these days to be
part of week 53 (%V) of the year 2009 (%G) ; week 01 of ISO 8601 year
2010 starts on Monday, 4 January 2010.
Perhaps you are looking for the ISO week date %V? And if just doing
calculations I suggest using UTC.
$ date -u -d 'Dec 31 2012 12:00 +0000' +%V
01
The 'ncal' program provides a useful but unusual way to display the
ISO week numbers:
$ ncal -A 1 -w 12 2012
December 2012 January 2013
Su 2 9 16 23 30 6 13 20 27
Mo 3 10 17 24 31 7 14 21 28
Tu 4 11 18 25 1 8 15 22 29
We 5 12 19 26 2 9 16 23 30
Th 6 13 20 27 3 10 17 24 31
Fr 7 14 21 28 4 11 18 25
Sa 1 8 15 22 29 5 12 19 26
48 49 50 51 52 1 1 2 3 4 5
You should also read the FAQ:
http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e
No one is ever happy with week numbers.
Bob
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#13372
; Package
coreutils
.
(Mon, 07 Jan 2013 23:36:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 13372 <at> debbugs.gnu.org (full text, mbox):
----- Original Message -----
> You are using %W which is described as:
>
> `%W'
> week number of year, with Monday as first day of week
> (`00'...`53'). Days in a new year preceding the first Monday
> are
> in week zero.
>
> And so:
>
> December 2012
> Mo Tu We Th Fr Sa Su
> 24 25 26 27 28 29 30 <-- week 52
> 31 <-- week 53
> January 2013
> Mo Tu We Th Fr Sa Su
> 1 2 3 4 5 6 <-- week 0
> 7 8 9 10 11 12 13 <-- week 1
> 14 15 16 17 18 19 20 <-- week 2
> 21 22 23 24 25 26 27
> 28 29 30 31
>
> Since you are reporting your current time as Jan 7 then Dec 31 would
> be last week. Dec 31 would be week 53.
>
> $ env TZ=Australia/Sydney date -d 'last week' -R
> Mon, 31 Dec 2012 16:59:04 +1100
>
> And so:
>
> $ env TZ=Australia/Sydney date -d 'last week' +%W
> 53
>
> $ env TZ=Australia/Sydney date -d 'Dec 31 2012 12:00 +0000' +%W
> 53
>
> There are multiple different definitions for week numbers depending
> upon weeks starting on Sunday, starting on Monday, and so forth.
>
> Also related are:
>
> `%U'
> week number of year, with Sunday as the first day of the week
> (`00'...`53'). Days in a new year preceding the first Sunday
> are
> in week zero.
>
> `%V'
> ISO week number, that is, the week number of year, with Monday
> as
> the first day of the week (`01'...`53'). If the week containing
> January 1 has four or more days in the new year, then it is
> considered week 1; otherwise, it is week 53 of the previous
> year,
> and the next week is week 1. (See the ISO 8601 standard.)
>
> You might want to look at the strftime man page for an alternate
> description:
>
> man 3 strftime
>
> %U The week number of the current year as a decimal
> number, range
> 00 to 53, starting with the first Sunday as the first
> day of
> week 01. See also %V and %W.
>
> %V The ISO 8601 week number (see NOTES) of the current
> year as a
> decimal number, range 01 to 53, where week 1 is the
> first week
> that has at least 4 days in the new year. See also
> %U and %W.
> (SU)
>
> %W The week number of the current year as a decimal
> number, range
> 00 to 53, starting with the first Monday as the first
> day of
> week 01.
>
> ISO 8601 Week Dates
> %G, %g, and %V yield values calculated from the week-based
> year defined
> by the ISO 8601 standard. In this system, weeks start on a
> Monday, and
> are numbered from 01, for the first week, up to 52 or 53, for
> the last
> week. Week 1 is the first week where four or more days fall
> within the
> new year (or, synonymously, week 01 is: the first week of the
> year that
> contains a Thursday; or, the week that has 4 January in
> it). When
> three of fewer days of the first calendar week of the new
> year fall
> within that year, then the ISO 8601 week-based system counts
> those days
> as part of week 53 of the preceding year. For example, 1
> January 2010
> is a Friday, meaning that just three days of that calendar
> week fall in
> 2010. Thus, the ISO 8601 week-based system considers these
> days to be
> part of week 53 (%V) of the year 2009 (%G) ; week 01 of ISO
> 8601 year
> 2010 starts on Monday, 4 January 2010.
>
> Perhaps you are looking for the ISO week date %V? And if just doing
> calculations I suggest using UTC.
>
> $ date -u -d 'Dec 31 2012 12:00 +0000' +%V
> 01
>
> The 'ncal' program provides a useful but unusual way to display the
> ISO week numbers:
>
> $ ncal -A 1 -w 12 2012
> December 2012 January 2013
> Su 2 9 16 23 30 6 13 20 27
> Mo 3 10 17 24 31 7 14 21 28
> Tu 4 11 18 25 1 8 15 22 29
> We 5 12 19 26 2 9 16 23 30
> Th 6 13 20 27 3 10 17 24 31
> Fr 7 14 21 28 4 11 18 25
> Sa 1 8 15 22 29 5 12 19 26
> 48 49 50 51 52 1 1 2 3 4 5
>
> You should also read the FAQ:
>
> http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e
>
> No one is ever happy with week numbers.
>
> Bob
>
Bob, many thanks for in depth explanation! Please close this is not a bug.
--
Tomas Dabašinskas | Engineering Content Services | Red Hat Asia Pacific
☺: tomas | ☎: +61(0)7 3514 8204 | ✉: tomas <at> redhat.com
Added tag(s) notabug.
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Tue, 08 Jan 2013 00:10:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
13372 <at> debbugs.gnu.org and Tomas Dabašinskas <tomas <at> redhat.com>
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Tue, 08 Jan 2013 00:10:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 05 Feb 2013 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 12 years and 135 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.