Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9fe8ee

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 parente652d2c commitb9fe8ee

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)

[8]ページ先頭

©2009-2025 Movatter.jp