Thread: BUG #16419: wrong parsing BC year in to_date() function
The following bug has been logged on the website: Bug reference: 16419 Logged by: Saeed Hubaishan Email address: dar_alathar@hotmail.com PostgreSQL version: 12.2 Operating system: Windows 10x64 Description: select to_date('-1-01-01','yyyy-mm-dd'); will get 0002-01-01 BC
The following bug has been logged on the website:
Bug reference: 16419
Logged by: Saeed Hubaishan
Email address: dar_alathar@hotmail.com
PostgreSQL version: 12.2
Operating system: Windows 10x64
Description:
select to_date('-1-01-01','yyyy-mm-dd');
will get
0002-01-01 BC
رد: BUG #16419: wrong parsing BC year in to_date() function
Any one suppose that these functions return the same:
make_date(-1,1,1)
to_date('-1-01-01','yyyy-mm-dd')
But make_date will give 0001-01-01 BC
And to_date will give 0002-01-01 BC
If you think this is right behavior I think this must be documented
من: David G. Johnston <david.g.johnston@gmail.com>
تم الإرسال: Thursday, May 7, 2020 1:45:14 AM
إلى: dar_alathar@hotmail.com <dar_alathar@hotmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
الموضوع: Re: BUG #16419: wrong parsing BC year in to_date() function
On Wed, May 6, 2020 at 2:58 PM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 16419
Logged by: Saeed Hubaishan
Email address: dar_alathar@hotmail.com
PostgreSQL version: 12.2
Operating system: Windows 10x64
Description:
select to_date('-1-01-01','yyyy-mm-dd');
will get
0002-01-01 BC
Yep...
select to_date('1','YYYY')::text; // Year 1 AD
select to_date('0','YYYY')::text; // Year 1 BC (there is no year zero)
select to_date('-1','YYYY')::text; // Year 2 BC
to_date tries very hard to not error - if you need to use it make sure your data conforms to the format you specify.
David J.
من: David G. Johnston
إرسال: الخميس, 14 رمضان, 1441 01:45 ص
الموضوع: Re: BUG #16419: wrong parsing BC year in to_date() function
On Wed, May 6, 2020 at 2:58 PM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 16419
Logged by: Saeed Hubaishan
Email address: dar_alathar@hotmail.com
PostgreSQL version: 12.2
Operating system: Windows 10x64
Description:
select to_date('-1-01-01','yyyy-mm-dd');
will get
0002-01-01 BC
Yep...
select to_date('1','YYYY')::text; // Year 1 AD
select to_date('0','YYYY')::text; // Year 1 BC (there is no year zero)
select to_date('-1','YYYY')::text; // Year 2 BC
to_date tries very hard to not error - if you need to use it make sure your data conforms to the format you specify.
David J.
Attachment
Any one suppose that these functions return the same:
make_date(-1,1,1)
to_date('-1-01-01','yyyy-mm-dd')But make_date will give 0001-01-01 BC
And to_date will give 0002-01-01 BC
It does this seemingly by subtracting one from the year, making it positive, then (I infer) appending "BC" to the result. Thus for the year "-1" it yields "0002-01-01 BC"
* There is no 0 AD. Years go from 1 BC to 1 AD, so we make it
* positive and map year == -1 to year zero, and shift all negative
* years up one. For interval years, we just return the year.
*/
رد: BUG #16419: wrong parsing BC year in to_date() function
To make "to_date" work as "make_date" with negative years these llines:
if (tmfc.bc && tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1);
must be changed to:
if (tmfc.bc && tm->tm_year > 0)
{
tm->tm_year = -(tm->tm_year - 1);
}
else if (tm->tm_year < 0) {
tm->tm_year ++;
}
رد: BUG #16419: wrong parsing BC year in to_date() function
research how it behaves in the other database it tries to emulate and either document or possibly change the behavior in v14
As in https://stackoverflow.com/questions/6779521/how-do-i-insert-a-bc-date-into-oracle and http://rwijk.blogspot.com/2008/10/year-zero.html
In Oracle
to_date('-4700/01/01','syyyy/mm/dd')
returns
01/01/4700 BC
In documents https://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_commands_1029.htm#OLADM780
YEAR SYEAR |
| Year, spelled out; |
YYYY SYYYY |
| 4-digit year; |