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

From: Robert Creager <Robert_Creager(at)LogicalChaos(dot)org>
To: Dirk Raetzel <d00273(at)spaetzle(dot)de>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dirk Raetzel <d00273(at)spaetzle(dot)de>, 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-29 13:42:09
Message-ID: 20050329064209.08387289@thunder.logicalchaos.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches

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.

Cheers,
Rob

--
06:39:48 up 1 day, 3 min, 9 users, load average: 0.10, 0.24, 0.30
Linux 2.6.5-02 #8 SMP Mon Jul 12 21:34:44 MDT 2004

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Mehul Doshi-A20614 2005-03-29 16:14:10 Enhancement: Remove NT/Interactive from Power Users Group
Previous Message Greg Sabino Mullane 2005-03-29 12:25:23 Re: Background writer process terminating

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2005-03-29 20:35:50 Re: pgsql: Add URL of how to report bugs:
Previous Message Dirk Raetzel 2005-03-29 05:43:53 Re: [BUGS] BUG #1563: wrong week returnded by date_trunc('week',