aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2005-07-04 14:12:45 +0000
committerBruce Momjian <bruce@momjian.us>2005-07-04 14:12:45 +0000
commit0a056c3716065b044c5b0ab4e724b6f7d3c5721b (patch)
tree353243dbaf8197b81059c7413ccc5103b5293e30 /src
parentbb630623a4935ef7486e1c1fb582ff47ecc0910b (diff)
downloadpostgresql-0a056c3716065b044c5b0ab4e724b6f7d3c5721b.tar.gz
postgresql-0a056c3716065b044c5b0ab4e724b6f7d3c5721b.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/timestamp.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 6ade3fb71fd..491a6ac14a3 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.117.4.2 2005/05/26 02:10:02 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.117.4.3 2005/07/04 14:12:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2755,9 +2755,12 @@ timestamp_trunc(PG_FUNCTION_ARGS)
/*
* If it is week 52/53 and the month is January,
* 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)
--tm->tm_year;
+ if (woy <= 1 && tm->tm_mon == 12)
+ ++tm->tm_year;
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
tm->tm_hour = 0;
tm->tm_min = 0;
@@ -2886,9 +2889,12 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
/*
* If it is week 52/53 and the month is January,
* 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)
--tm->tm_year;
+ if (woy <= 1 && tm->tm_mon == 12)
+ ++tm->tm_year;
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
tm->tm_hour = 0;
tm->tm_min = 0;