Re: [BUGS] BUG #1563: wrong week returnded by date_trunc('week',

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Robert Creager <Robert_Creager(at)LogicalChaos(dot)org>
Cc: Dirk Raetzel <d00273(at)spaetzle(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #1563: wrong week returnded by date_trunc('week',
Date: 2005-03-30 06:06:20
Message-ID: 200503300606.j2U66K914935@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches

Robert Creager wrote:
-- Start of PGP signed section.
> When grilled further on (Tue, 29 Mar 2005 07:43:53 +0200),
> Dirk Raetzel <d00273(at)spaetzle(dot)de> confessed:
>
> >
> >
> > On Mon, 28 Mar 2005, Bruce Momjian wrote:
> >
> > > I have developed a patch to fix the problem. Instead of changing the
> > > API, I added code to decrement the year when the week number was 53 and
> > > the month was January. It corrected the problem:
> >
> > The problem arises as well when week number is 52 as in '2006-01-01'.
>
> Try these at the least:
>
> select date_trunc_week( '2004-01-01' ); -- should be 2003-12-29 00:00:00
> select date_trunc_week( '2005-01-01' ); -- should be 2004-12-27 00:00:00
> select date_trunc_week( '2005-06-01' ); -- should be 2005-05-30 00:00:00
> select date_trunc_week( '2006-01-01' ); -- should be 2005-12-26 00:00:00
> select date_trunc_week( '2007-01-01' ); -- should be 2007-01-01 00:00:00
>
> If it helps, look earlier in this thread for a (overly complicated?) version in
> plpgsql.

Wow, an early January date can be part of the 52nd week of the previous
year too.

Here is a new patch, with a documentation mention.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 4.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2005-03-30 06:35:40 Re: [BUGS] Enhancement: Remove NT/Interactive from Power Users Group
Previous Message Neil Conway 2005-03-30 05:06:44 Re: BUG #1567: can't hide password with pg_autovacuum

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2005-03-30 13:53:07 minor nodeHash cleanup
Previous Message Tom Lane 2005-03-30 04:48:57 Re: unused variable ShmemBootstrap