mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Fix EXTRACT(ISOYEAR FROM timestamp) for years BC.
The test cases added by commit 26ae3aa80
exposed an old oversight in
timestamp[tz]_part: they didn't correct the result of date2isoyear()
for BC years, so that we produced an off-by-one answer for such years.
Fix that, and back-patch to all supported branches.
Discussion: https://postgr.es/m/SG2PR06MB37762CAE45DB0F6CA7001EA9B6550@SG2PR06MB3776.apcprd06.prod.outlook.com
This commit is contained in:
@ -4373,6 +4373,7 @@ date2isoweek(int year, int mon, int mday)
|
||||
/* date2isoyear()
|
||||
*
|
||||
* Returns ISO 8601 year number.
|
||||
* Note: zero or negative results follow the year-zero-exists convention.
|
||||
*/
|
||||
int
|
||||
date2isoyear(int year, int mon, int mday)
|
||||
@ -4647,6 +4648,9 @@ timestamp_part(PG_FUNCTION_ARGS)
|
||||
|
||||
case DTK_ISOYEAR:
|
||||
result = date2isoyear(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||
/* Adjust BC years */
|
||||
if (result <= 0)
|
||||
result -= 1;
|
||||
break;
|
||||
|
||||
case DTK_DOW:
|
||||
@ -4843,6 +4847,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
||||
|
||||
case DTK_ISOYEAR:
|
||||
result = date2isoyear(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||
/* Adjust BC years */
|
||||
if (result <= 0)
|
||||
result -= 1;
|
||||
break;
|
||||
|
||||
case DTK_DOW:
|
||||
|
Reference in New Issue
Block a user