pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13848: 2016 Week Number Error
4+ messages / 4 participants
[nested] [flat]

* BUG #13848: 2016 Week Number Error
@ 2016-01-05 19:32 maxk@yelp.com
  2016-01-07 18:36 ` Re: BUG #13848: 2016 Week Number Error Francisco Olarte <folarte@peoplecall.com>
  2016-01-07 18:37 ` Re: BUG #13848: 2016 Week Number Error John McKown <john.archie.mckown@gmail.com>
  2016-01-07 18:40 ` Re: BUG #13848: 2016 Week Number Error Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 3 replies; 4+ messages in thread

From: maxk@yelp.com @ 2016-01-05 19:32 UTC (permalink / raw)
  To: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13848: 2016 Week Number Error
  2016-01-05 19:32 BUG #13848: 2016 Week Number Error maxk@yelp.com
@ 2016-01-07 18:36 ` Francisco Olarte <folarte@peoplecall.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Francisco Olarte @ 2016-01-07 18:36 UTC (permalink / raw)
  To: maxk@yelp.com; +Cc: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13848: 2016 Week Number Error
  2016-01-05 19:32 BUG #13848: 2016 Week Number Error maxk@yelp.com
@ 2016-01-07 18:37 ` John McKown <john.archie.mckown@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: John McKown @ 2016-01-07 18:37 UTC (permalink / raw)
  To: maxk@yelp.com; +Cc: pgsql-bugs

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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #13848: 2016 Week Number Error
  2016-01-05 19:32 BUG #13848: 2016 Week Number Error maxk@yelp.com
@ 2016-01-07 18:40 ` Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2016-01-07 18:40 UTC (permalink / raw)
  To: maxk@yelp.com; +Cc: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2016-01-07 18:40 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 19:32 BUG #13848: 2016 Week Number Error maxk@yelp.com
2016-01-07 18:36 ` Francisco Olarte <folarte@peoplecall.com>
2016-01-07 18:37 ` John McKown <john.archie.mckown@gmail.com>
2016-01-07 18:40 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox