aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-07-17 00:55:37 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-07-17 00:55:37 +0000
commit764f72dc823edb3f8bdf387501ce4c12dedd2369 (patch)
tree01838a17f094eb1ac2a0f99102002adbff063605 /src
parent93236b58e088cd2151540528d484da9ad82e48c8 (diff)
downloadpostgresql-764f72dc823edb3f8bdf387501ce4c12dedd2369.tar.gz
postgresql-764f72dc823edb3f8bdf387501ce4c12dedd2369.zip
Make EXTRACT(TIMEZONE) and SET/SHOW TIMEZONE follow the SQL convention
for the sign of timezone offsets, ie, positive is east from UTC. These were previously out of step with other operations that accept or show timezones, such as I/O of timestamptz values.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/variable.c13
-rw-r--r--src/backend/utils/adt/date.c13
-rw-r--r--src/backend/utils/adt/nabstime.c16
-rw-r--r--src/backend/utils/adt/timestamp.c13
-rw-r--r--src/include/miscadmin.h6
-rw-r--r--src/include/utils/datetime.h17
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt.h15
7 files changed, 62 insertions, 31 deletions
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 41bc3f58bc2..9a525b14b89 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.81 2003/07/15 19:34:43 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.82 2003/07/17 00:55:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -429,7 +429,8 @@ assign_timezone(const char *value, bool doit, bool interactive)
}
if (doit)
{
- CTimeZone = interval->time;
+ /* Here we change from SQL to Unix sign convention */
+ CTimeZone = - interval->time;
HasCTZSet = true;
}
pfree(interval);
@@ -444,7 +445,8 @@ assign_timezone(const char *value, bool doit, bool interactive)
{
if (doit)
{
- CTimeZone = hours * 3600;
+ /* Here we change from SQL to Unix sign convention */
+ CTimeZone = - hours * 3600;
HasCTZSet = true;
}
}
@@ -557,7 +559,8 @@ assign_timezone(const char *value, bool doit, bool interactive)
return NULL;
if (HasCTZSet)
- snprintf(result, sizeof(tzbuf), "%.5f", (double) CTimeZone / 3600.0);
+ snprintf(result, sizeof(tzbuf), "%.5f",
+ (double) (-CTimeZone) / 3600.0);
else if (tzbuf[0] == 'T')
strcpy(result, tzbuf + 3);
else
@@ -579,7 +582,7 @@ show_timezone(void)
Interval interval;
interval.month = 0;
- interval.time = CTimeZone;
+ interval.time = - CTimeZone;
tzn = DatumGetCString(DirectFunctionCall1(interval_out,
IntervalPGetDatum(&interval)));
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index fa03b577891..ea1768be79d 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.83 2003/06/16 18:56:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.84 2003/07/17 00:55:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2031,17 +2031,18 @@ timetz_part(PG_FUNCTION_ARGS)
switch (val)
{
case DTK_TZ:
- result = tz;
+ result = -tz;
break;
case DTK_TZ_MINUTE:
- result = tz / 60;
- TMODULO(result, dummy, 60e0);
+ result = -tz;
+ result /= 60;
+ FMODULO(result, dummy, 60e0);
break;
case DTK_TZ_HOUR:
- dummy = tz;
- TMODULO(dummy, result, 3600e0);
+ dummy = -tz;
+ FMODULO(dummy, result, 3600e0);
break;
case DTK_MICROSEC:
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index fe14c9bec4f..88943a76676 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.108 2003/05/12 23:08:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.109 2003/07/17 00:55:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -825,12 +825,14 @@ reltimesend(PG_FUNCTION_ARGS)
static void
reltime2tm(RelativeTime time, struct tm * tm)
{
- TMODULO(time, tm->tm_year, 31557600);
- TMODULO(time, tm->tm_mon, 2592000);
- TMODULO(time, tm->tm_mday, 86400);
- TMODULO(time, tm->tm_hour, 3600);
- TMODULO(time, tm->tm_min, 60);
- TMODULO(time, tm->tm_sec, 1);
+ double dtime = time;
+
+ FMODULO(dtime, tm->tm_year, 31557600);
+ FMODULO(dtime, tm->tm_mon, 2592000);
+ FMODULO(dtime, tm->tm_mday, 86400);
+ FMODULO(dtime, tm->tm_hour, 3600);
+ FMODULO(dtime, tm->tm_min, 60);
+ FMODULO(dtime, tm->tm_sec, 1);
}
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 6cf4f3667cf..4ee6e953240 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.85 2003/07/04 18:21:13 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.86 2003/07/17 00:55:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3080,17 +3080,18 @@ timestamptz_part(PG_FUNCTION_ARGS)
switch (val)
{
case DTK_TZ:
- result = tz;
+ result = -tz;
break;
case DTK_TZ_MINUTE:
- result = tz / 60;
- TMODULO(result, dummy, 60e0);
+ result = -tz;
+ result /= 60;
+ FMODULO(result, dummy, 60e0);
break;
case DTK_TZ_HOUR:
- dummy = tz;
- TMODULO(dummy, result, 3600e0);
+ dummy = -tz;
+ FMODULO(dummy, result, 3600e0);
break;
case DTK_MICROSEC:
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 213d2581333..cfe065ffcf0 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.125 2003/06/27 19:08:38 tgl Exp $
+ * $Id: miscadmin.h,v 1.126 2003/07/17 00:55:37 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to
@@ -147,7 +147,9 @@ extern DLLIMPORT Oid MyDatabaseId;
* EuroDates if client prefers dates interpreted and written w/European conventions.
*
* HasCTZSet is true if user has set timezone as a numeric offset from UTC.
- * If so, CTimeZone is the timezone offset in seconds.
+ * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
+ * sign convention, ie, positive offset is west of UTC, rather than the
+ * SQL-ish convention that positive is east of UTC).
*/
#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 7623095f09c..4a9443e1750 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: datetime.h,v 1.39 2003/05/18 01:06:26 tgl Exp $
+ * $Id: datetime.h,v 1.40 2003/07/17 00:55:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -196,12 +196,23 @@ typedef struct
} datetkn;
-/* TMODULO()
+/* FMODULO()
* Macro to replace modf(), which is broken on some platforms.
* t = input and remainder
* q = integer part
* u = divisor
*/
+#define FMODULO(t,q,u) \
+do { \
+ q = ((t < 0) ? ceil(t / u): floor(t / u)); \
+ if (q != 0) t -= rint(q * u); \
+} while(0)
+
+/* TMODULO()
+ * Like FMODULO(), but work on the timestamp datatype (either int64 or float8).
+ * We assume that int64 follows the C99 semantics for division (negative
+ * quotients truncate towards zero).
+ */
#ifdef HAVE_INT64_TIMESTAMP
#define TMODULO(t,q,u) \
do { \
@@ -211,7 +222,7 @@ do { \
#else
#define TMODULO(t,q,u) \
do { \
- q = ((t < 0)? ceil(t / u): floor(t / u)); \
+ q = ((t < 0) ? ceil(t / u): floor(t / u)); \
if (q != 0) t -= rint(q * u); \
} while(0)
#endif
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index 5f686202337..185f0b0c948 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -183,12 +183,23 @@ typedef struct
} datetkn;
-/* TMODULO()
+/* FMODULO()
* Macro to replace modf(), which is broken on some platforms.
* t = input and remainder
* q = integer part
* u = divisor
*/
+#define FMODULO(t,q,u) \
+do { \
+ q = ((t < 0) ? ceil(t / u): floor(t / u)); \
+ if (q != 0) t -= rint(q * u); \
+} while(0)
+
+/* TMODULO()
+ * Like FMODULO(), but work on the timestamp datatype (either int64 or float8).
+ * We assume that int64 follows the C99 semantics for division (negative
+ * quotients truncate towards zero).
+ */
#ifdef HAVE_INT64_TIMESTAMP
#define TMODULO(t,q,u) \
do { \
@@ -198,7 +209,7 @@ do { \
#else
#define TMODULO(t,q,u) \
do { \
- q = ((t < 0)? ceil(t / u): floor(t / u)); \
+ q = ((t < 0) ? ceil(t / u): floor(t / u)); \
if (q != 0) t -= rint(q * u); \
} while(0)
#endif