Skip to content

Commit 191ef2b

Browse files
committed
Change EXTRACT(EPOCH FROM timestamp) so that a timestamp without time zone
is assumed to be in local time, not GMT. This improves consistency with other operations, which all assume local timezone when it matters. Per bug #897.
1 parent 3d1a1e8 commit 191ef2b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.78 2003/02/22 05:57:45 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.79 2003/02/27 21:36:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2865,13 +2865,26 @@ timestamp_part(PG_FUNCTION_ARGS)
28652865
switch (val)
28662866
{
28672867
case DTK_EPOCH:
2868+
{
2869+
int tz;
2870+
TimestampTz timestamptz;
2871+
2872+
/* convert to timestamptz to produce consistent results */
2873+
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
2874+
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE (tm)");
2875+
2876+
tz = DetermineLocalTimeZone(tm);
2877+
2878+
if (tm2timestamp(tm, fsec, &tz, &timestamptz) != 0)
2879+
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE");
2880+
28682881
#ifdef HAVE_INT64_TIMESTAMP
2869-
result = ((timestamp - SetEpochTimestamp()) / 1000000e0);
2882+
result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
28702883
#else
2871-
result = timestamp - SetEpochTimestamp();
2884+
result = timestamptz - SetEpochTimestamp();
28722885
#endif
28732886
break;
2874-
2887+
}
28752888
case DTK_DOW:
28762889
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
28772890
elog(ERROR, "Unable to encode TIMESTAMP");

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