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

Commitc4acbb8

Browse files
committed
timestamptz_trunc() should only recalculate the timezone when truncating
to DAY precision or coarser; leave the timezone alone when precision isHOUR or less. This avoids surprises for inputs near a DST transitiontime, as per example from Matthew Gabeler-Lee. (The only reason werecalculate at all is so that outputs that are supposed to representdays will come out as local midnight, and that's not relevant for sub-dayprecision.)
1 parent5ba04cd commitc4acbb8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 15 additions & 2 deletions
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.113 2004/08/30 02:54:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.114 2004/11/01 22:00:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2842,6 +2842,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
28422842
inttz;
28432843
inttype,
28442844
val;
2845+
boolredotz= false;
28452846
char*lowunits;
28462847
fsec_tfsec;
28472848
char*tzn;
@@ -2872,6 +2873,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
28722873
tm->tm_min=0;
28732874
tm->tm_sec=0;
28742875
fsec=0;
2876+
redotz= true;
28752877
break;
28762878
/* one may consider DTK_THOUSAND and DTK_HUNDRED... */
28772879
caseDTK_MILLENNIUM:
@@ -2885,12 +2887,14 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
28852887
tm->tm_year= ((tm->tm_year+999) /1000)*1000-999;
28862888
else
28872889
tm->tm_year=-((999- (tm->tm_year-1)) /1000)*1000+1;
2890+
/* FALL THRU */
28882891
caseDTK_CENTURY:
28892892
/* truncating to the century? as above: -100, 1, 101... */
28902893
if (tm->tm_year>0)
28912894
tm->tm_year= ((tm->tm_year+99) /100)*100-99;
28922895
else
28932896
tm->tm_year=-((99- (tm->tm_year-1)) /100)*100+1;
2897+
/* FALL THRU */
28942898
caseDTK_DECADE:
28952899

28962900
/*
@@ -2904,18 +2908,26 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
29042908
else
29052909
tm->tm_year=-((8- (tm->tm_year-1)) /10)*10;
29062910
}
2911+
/* FALL THRU */
29072912
caseDTK_YEAR:
29082913
tm->tm_mon=1;
2914+
/* FALL THRU */
29092915
caseDTK_QUARTER:
29102916
tm->tm_mon= (3* ((tm->tm_mon-1) /3))+1;
2917+
/* FALL THRU */
29112918
caseDTK_MONTH:
29122919
tm->tm_mday=1;
2920+
/* FALL THRU */
29132921
caseDTK_DAY:
29142922
tm->tm_hour=0;
2923+
redotz= true;/* for all cases >= DAY */
2924+
/* FALL THRU */
29152925
caseDTK_HOUR:
29162926
tm->tm_min=0;
2927+
/* FALL THRU */
29172928
caseDTK_MINUTE:
29182929
tm->tm_sec=0;
2930+
/* FALL THRU */
29192931
caseDTK_SECOND:
29202932
fsec=0;
29212933
break;
@@ -2941,7 +2953,8 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
29412953
result=0;
29422954
}
29432955

2944-
tz=DetermineLocalTimeZone(tm);
2956+
if (redotz)
2957+
tz=DetermineLocalTimeZone(tm);
29452958

29462959
if (tm2timestamp(tm,fsec,&tz,&result)!=0)
29472960
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp