summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/timestamp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-02-27 21:37:24 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-02-27 21:37:24 +0000
commit4b60df3aa61200f852b7e8be06492ed8e327bfc9 (patch)
tree381294f0e5f5d2385830683e19a9e75f05c034c4 /src/backend/utils/adt/timestamp.c
parentdb34282fe32469b8b1ce2eae2ff6287d2ee262bd (diff)
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.
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r--src/backend/utils/adt/timestamp.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 046d86c92f8..ee21aa03b56 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.74.2.2 2003/01/09 01:07:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.74.2.3 2003/02/27 21:37:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2861,13 +2861,26 @@ timestamp_part(PG_FUNCTION_ARGS)
switch (val)
{
case DTK_EPOCH:
+ {
+ int tz;
+ TimestampTz timestamptz;
+
+ /* convert to timestamptz to produce consistent results */
+ if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
+ elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE (tm)");
+
+ tz = DetermineLocalTimeZone(tm);
+
+ if (tm2timestamp(tm, fsec, &tz, &timestamptz) != 0)
+ elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE");
+
#ifdef HAVE_INT64_TIMESTAMP
- result = ((timestamp - SetEpochTimestamp()) / 1000000e0);
+ result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
#else
- result = timestamp - SetEpochTimestamp();
+ result = timestamptz - SetEpochTimestamp();
#endif
break;
-
+ }
case DTK_DOW:
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
elog(ERROR, "Unable to encode TIMESTAMP");