mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Fix date_trunct for December dates that are in the next year, e.g.:
SELECT date_trunc('week', '2002-12-31'::date); Backpatch to 8.0.X. Per report from Nick Johnson.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.128 2005/06/30 03:48:58 neilc Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.129 2005/07/04 14:38:31 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2793,9 +2793,12 @@ timestamp_trunc(PG_FUNCTION_ARGS)
|
|||||||
/*
|
/*
|
||||||
* If it is week 52/53 and the month is January,
|
* If it is week 52/53 and the month is January,
|
||||||
* then the week must belong to the previous year.
|
* then the week must belong to the previous year.
|
||||||
|
* Also, some December dates belong to the next year.
|
||||||
*/
|
*/
|
||||||
if (woy >= 52 && tm->tm_mon == 1)
|
if (woy >= 52 && tm->tm_mon == 1)
|
||||||
--tm->tm_year;
|
--tm->tm_year;
|
||||||
|
if (woy <= 1 && tm->tm_mon == 12)
|
||||||
|
++tm->tm_year;
|
||||||
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
tm->tm_min = 0;
|
tm->tm_min = 0;
|
||||||
@ -2924,9 +2927,12 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
|
|||||||
/*
|
/*
|
||||||
* If it is week 52/53 and the month is January,
|
* If it is week 52/53 and the month is January,
|
||||||
* then the week must belong to the previous year.
|
* then the week must belong to the previous year.
|
||||||
|
* Also, some December dates belong to the next year.
|
||||||
*/
|
*/
|
||||||
if (woy >= 52 && tm->tm_mon == 1)
|
if (woy >= 52 && tm->tm_mon == 1)
|
||||||
--tm->tm_year;
|
--tm->tm_year;
|
||||||
|
if (woy <= 1 && tm->tm_mon == 12)
|
||||||
|
++tm->tm_year;
|
||||||
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
||||||
tm->tm_hour = 0;
|
tm->tm_hour = 0;
|
||||||
tm->tm_min = 0;
|
tm->tm_min = 0;
|
||||||
|
Reference in New Issue
Block a user