Skip to content

Commit b9fe8ee

Browse files
committed
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.
1 parent e652d2c commit b9fe8ee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.128 2005/06/30 03:48:58 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.129 2005/07/04 14:38:31 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2793,9 +2793,12 @@ timestamp_trunc(PG_FUNCTION_ARGS)
27932793
/*
27942794
* If it is week 52/53 and the month is January,
27952795
* then the week must belong to the previous year.
2796+
* Also, some December dates belong to the next year.
27962797
*/
27972798
if (woy >= 52 && tm->tm_mon == 1)
27982799
--tm->tm_year;
2800+
if (woy <= 1 && tm->tm_mon == 12)
2801+
++tm->tm_year;
27992802
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
28002803
tm->tm_hour = 0;
28012804
tm->tm_min = 0;
@@ -2924,9 +2927,12 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
29242927
/*
29252928
* If it is week 52/53 and the month is January,
29262929
* then the week must belong to the previous year.
2930+
* Also, some December dates belong to the next year.
29272931
*/
29282932
if (woy >= 52 && tm->tm_mon == 1)
29292933
--tm->tm_year;
2934+
if (woy <= 1 && tm->tm_mon == 12)
2935+
++tm->tm_year;
29302936
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
29312937
tm->tm_hour = 0;
29322938
tm->tm_min = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy