mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Fix make_timestamp[tz] to accept negative years as meaning BC.
Previously we threw an error. But make_date already allowed the case, so it is inconsistent as well as unhelpful for make_timestamp not to. Both functions continue to reject year zero. Code and test fixes by Peter Eisentraut, doc changes by me Discussion: https://postgr.es/m/13c0992c-f15a-a0ca-d839-91d3efd965d9@2ndquadrant.com
This commit is contained in:
@ -556,17 +556,21 @@ make_timestamp_internal(int year, int month, int day,
|
||||
TimeOffset date;
|
||||
TimeOffset time;
|
||||
int dterr;
|
||||
bool bc = false;
|
||||
Timestamp result;
|
||||
|
||||
tm.tm_year = year;
|
||||
tm.tm_mon = month;
|
||||
tm.tm_mday = day;
|
||||
|
||||
/*
|
||||
* Note: we'll reject zero or negative year values. Perhaps negatives
|
||||
* should be allowed to represent BC years?
|
||||
*/
|
||||
dterr = ValidateDate(DTK_DATE_M, false, false, false, &tm);
|
||||
/* Handle negative years as BC */
|
||||
if (tm.tm_year < 0)
|
||||
{
|
||||
bc = true;
|
||||
tm.tm_year = -tm.tm_year;
|
||||
}
|
||||
|
||||
dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
|
||||
|
||||
if (dterr != 0)
|
||||
ereport(ERROR,
|
||||
|
Reference in New Issue
Block a user