BUG #13848: 2016 Week Number Error

Started by Nonameover 10 years ago4 messagesbugs
Jump to latest
#1Noname
maxk@yelp.com

The following bug has been logged on the website:

Bug reference: 13848
Logged by: Max Kulinich
Email address: maxk@yelp.com
PostgreSQL version: 9.4.5
Operating system: OSX
Description:

SELECT EXTRACT(Week FROM current_date) = 1 instead of 2 Week numbers are all
off

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Francisco Olarte
folarte@peoplecall.com
In reply to: Noname (#1)
Re: BUG #13848: 2016 Week Number Error

On Tue, Jan 5, 2016 at 8:32 PM, <maxk@yelp.com> wrote:

The following bug has been logged on the website:

Bug reference: 13848
Logged by: Max Kulinich
Email address: maxk@yelp.com
PostgreSQL version: 9.4.5
Operating system: OSX
Description:

SELECT EXTRACT(Week FROM current_date) = 1 instead of 2 Week numbers are all
off

If you did on Jan 5, it was correct.

RTFM, from http://www.postgresql.org/docs/9.4/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

week

The number of the ISO 8601 week-numbering week of the year. By
definition, ISO weeks start on Mondays and the first week of a year
contains January 4 of that year. In other words, the first Thursday of
a year is in week 1 of that year.

In the ISO week-numbering system, it is possible for early-January
dates to be part of the 52nd or 53rd week of the previous year, and
for late-December dates to be part of the first week of the next year.
For example, 2005-01-01 is part of the 53rd week of year 2004, and
2006-01-01 is part of the 52nd week of year 2005, while 2012-12-31 is
part of the first week of 2013. It's recommended to use the isoyear
field together with week to get consistent results.
<<<
January 4 was a monday, so week from 4 to 10 is 1. 1,2,3 of jan belong
to week 53 of 2015 ( as even my dead-tree calendar shows ).

=> select extract(week from '2016-01-05'::date), extract(isoyear from
'2016-01-05'::date);
date_part | date_part
-----------+-----------
1 | 2016
(1 row)

=> select extract(week from '2016-01-01'::date), extract(isoyear from
'2016-01-01'::date);
date_part | date_part
-----------+-----------
53 | 2015
(1 row)

=> select extract(week from '2016-01-03'::date), extract(isoyear from
'2016-01-03'::date);
date_part | date_part
-----------+-----------
53 | 2015
(1 row)

=> select extract(week from '2016-01-04'::date), extract(isoyear from
'2016-01-04'::date);
date_part | date_part
-----------+-----------
1 | 2016
(1 row)

Francisco Olarte.

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3John McKown
john.archie.mckown@gmail.com
In reply to: Noname (#1)
Re: BUG #13848: 2016 Week Number Error

On Tue, Jan 5, 2016 at 1:32 PM, <maxk@yelp.com> wrote:

The following bug has been logged on the website:

Bug reference: 13848
Logged by: Max Kulinich
Email address: maxk@yelp.com
PostgreSQL version: 9.4.5
Operating system: OSX
Description:

SELECT EXTRACT(Week FROM current_date) = 1 instead of 2 Week numbers are
all
off

​This looks correct to me.

http://www.postgresql.org/docs/9.5/interactive/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
<quote>
week

The number of the ISO 8601 week-numbering week of the year. By definition,
ISO weeks start on Mondays and the first week of a year contains January 4
of that year. In other words, the first Thursday of a year is in week 1 of
that year.

In the ISO week-numbering system, it is possible for early-January dates to
be part of the 52nd or 53rd week of the previous year, and for
late-December dates to be part of the first week of the next year. For
example, 2005-01-01 is part of the 53rd week of year 2004, and 2006-01-01 is
part of the 52nd week of year 2005, while 2012-12-31 is part of the first
week of 2013. It's recommended to use the isoyear field together with week to
get consistent results.
</quote>

​Jan 1, 2016 was on ​a Friday. The first Thursday of 2016 is 7 Jan. ISO
calendars start on a Monday (unlike US calendars which start on a Sunday),
so the ISO first week of 2016 is Jan 4, 2016 to Jan 10, 2016.

--
Werner Heisenberg is driving down the autobahn. A police officer pulls
him over. The officer says, "Excuse me, sir, do you know how fast you
were going?"
"No," replies Dr. Heisenberg, "but I know where I am."

Computer Science is the only discipline in which we view adding a new wing
to a building as being maintenance -- Jim Horning

Schrodinger's backup: The condition of any backup is unknown until a
restore is attempted.

He's about as useful as a wax frying pan.

Maranatha! <><
John McKown

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noname (#1)
Re: BUG #13848: 2016 Week Number Error

maxk@yelp.com writes:

SELECT EXTRACT(Week FROM current_date) = 1 instead of 2 Week numbers are all
off

Not a bug. See the manual's definition of this field:

: The number of the ISO 8601 week-numbering week of the year. By
: definition, ISO weeks start on Mondays and the first week of a year
: contains January 4 of that year. In other words, the first Thursday of a
: year is in week 1 of that year.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs