diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-23 22:54:03 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-23 22:54:03 +0000 |
commit | 2cfb3b6d4d59dabd401b658023629d15688f8493 (patch) | |
tree | b7b19abb60a0b6b076881f85a4ff4433ebf57572 | |
parent | ca1e578d62e21d1aef13e6b556f70fbf77216bfe (diff) | |
download | postgresql-2cfb3b6d4d59dabd401b658023629d15688f8493.tar.gz |
Repair two TIME WITH TIME ZONE bugs found by Dennis Vshivkov. Comparison
of timetz values misbehaved in --enable-integer-datetime cases, and
EXTRACT(EPOCH) subtracted the zone instead of adding it in all cases.
Backpatch to all supported releases (except --enable-integer-datetime code
does not exist in 7.2).
-rw-r--r-- | src/backend/utils/adt/date.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 1d710c5620..59c66bb0a6 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.73.2.7 2003/07/24 04:38:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.73.2.8 2005/04/23 22:54:03 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1414,12 +1414,20 @@ timetz_scale(PG_FUNCTION_ARGS) static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2) { + /* Primary sort is by true (GMT-equivalent) time */ +#ifdef HAVE_INT64_TIMESTAMP + int64 t1, + t2; + + t1 = time1->time + (time1->zone * INT64CONST(1000000)); + t2 = time2->time + (time2->zone * INT64CONST(1000000)); +#else double t1, t2; - /* Primary sort is by true (GMT-equivalent) time */ t1 = time1->time + time1->zone; t2 = time2->time + time2->zone; +#endif if (t1 > t2) return 1; @@ -1986,9 +1994,9 @@ timetz_part(PG_FUNCTION_ARGS) else if ((type == RESERV) && (val == DTK_EPOCH)) { #ifdef HAVE_INT64_TIMESTAMP - result = ((time->time / 1000000e0) - time->zone); + result = ((time->time / 1000000e0) + time->zone); #else - result = (time->time - time->zone); + result = (time->time + time->zone); #endif } else |