Re: [BUGS] CC Date format code defaults to current centry

Lists: pgsql-bugspgsql-patches
From: Joe Brown <joebrown(at)rclooke(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: CC Date format code defaults to current centry
Date: 2005-03-08 17:40:02
Message-ID: 422DE372.1080303@rclooke.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-patches

joe=> select to_date('19450323','CCYYMMDD');
to_date
------------
2045-03-23
(1 row)

joe=> select to_date('19450323','YYYYMMDD');
to_date
------------
1945-03-23
(1 row)

I thought the former would be "more" correct. But it seems I am mistaken.


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Joe Brown <joebrown(at)rclooke(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: CC Date format code defaults to current centry
Date: 2005-03-14 02:24:33
Message-ID: 200503140224.j2E2OXC14497@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-patches

Joe Brown wrote:
> joe=> select to_date('19450323','CCYYMMDD');
> to_date
> ------------
> 2045-03-23
> (1 row)
>
> joe=> select to_date('19450323','YYYYMMDD');
> to_date
> ------------
> 1945-03-23
> (1 row)
>
> I thought the former would be "more" correct. But it seems I am mistaken.

Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.

--
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


From: Andre Maasikas <andre(at)abs(dot)ee>
To:
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: CC Date format code defaults to current centry
Date: 2005-03-14 11:11:58
Message-ID: 4235717E.5050304@abs.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-patches

Bruce Momjian wrote:
> Joe Brown wrote:
>
>>joe=> select to_date('19450323','CCYYMMDD');
>> to_date
>>------------
>> 2045-03-23
>>(1 row)
>>
>>joe=> select to_date('19450323','YYYYMMDD');
>> to_date
>>------------
>> 1945-03-23
>>(1 row)
>>
>>I thought the former would be "more" correct. But it seems I am mistaken.
>
>
> Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.
>
Yes, but the other way around: to_date('19450323','CCYYMMDD')
shoold be a year in the 19th century?

ps another db seems to disallow CC on input - maybe because one can
get into weird situations like to_date('2005 18','YYYY CC') or something
similar.

Andre


From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: List pgsql-patches <pgsql-patches(at)postgreSQL(dot)org>
Subject: Re: [BUGS] CC Date format code defaults to current centry
Date: 2005-03-17 09:50:51
Message-ID: 1111053051.4169.242.camel@petra
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-patches

On Sun, 2005-03-13 at 21:24 -0500, Bruce Momjian wrote:
> Joe Brown wrote:
> > joe=> select to_date('19450323','CCYYMMDD');
> > to_date
> > ------------
> > 2045-03-23
> > (1 row)
> >
> > joe=> select to_date('19450323','YYYYMMDD');
> > to_date
> > ------------
> > 1945-03-23
> > (1 row)
> >
> > I thought the former would be "more" correct. But it seems I am mistaken.
>
> Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.

It ignored CC value if there was YY (YYYY, ..). And YY=45 is 2045:

/*
* 2-digit year
*/
if (tmfc->year < 70)
tmfc->year += 2000;
else
tmfc->year += 1900;

I think it's very special case when you define YY and CC and code
should detects it and counts year as (CC-1)*100+YY. The right answers:

CC+YY

test=# select to_date('20450112', 'CCYYDDMM');
to_date
------------
1945-12-01

CC+Y

test=# select to_date('2090112', 'CCYDDMM');
to_date
------------
1909-12-01

For YYY/YYYY it ignore CC option.

The patch (with docs changes) is in the attachment.

Karel

--
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>

Attachment Content-Type Size
formatting-17032005.patch.gz application/x-gzip 1.3 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, List pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [BUGS] CC Date format code defaults to current centry
Date: 2005-03-25 16:09:30
Message-ID: 24785.1111766970@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-patches

Karel Zak <zakkr(at)zf(dot)jcu(dot)cz> writes:
> I think it's very special case when you define YY and CC and code
> should detects it and counts year as (CC-1)*100+YY. The right answers:
> ...
> The patch (with docs changes) is in the attachment.

Applied to HEAD and 8.0.

regards, tom lane