Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 35f9b46

Browse files
committed
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).
1 parent 0e99be1 commit 35f9b46

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/backend/utils/adt/date.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.104 2004/12/31 22:01:21 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.105 2005/04/23 22:53:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1869,12 +1869,20 @@ timetz_scale(PG_FUNCTION_ARGS)
18691869
static int
18701870
timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
18711871
{
1872+
/* Primary sort is by true (GMT-equivalent) time */
1873+
#ifdef HAVE_INT64_TIMESTAMP
1874+
int64 t1,
1875+
t2;
1876+
1877+
t1 = time1->time + (time1->zone * INT64CONST(1000000));
1878+
t2 = time2->time + (time2->zone * INT64CONST(1000000));
1879+
#else
18721880
double t1,
18731881
t2;
18741882

1875-
/* Primary sort is by true (GMT-equivalent) time */
18761883
t1 = time1->time + time1->zone;
18771884
t2 = time2->time + time2->zone;
1885+
#endif
18781886

18791887
if (t1 > t2)
18801888
return 1;
@@ -2443,9 +2451,9 @@ timetz_part(PG_FUNCTION_ARGS)
24432451
else if ((type == RESERV) && (val == DTK_EPOCH))
24442452
{
24452453
#ifdef HAVE_INT64_TIMESTAMP
2446-
result = ((time->time / 1000000e0) - time->zone);
2454+
result = ((time->time / 1000000e0) + time->zone);
24472455
#else
2448-
result = (time->time - time->zone);
2456+
result = (time->time + time->zone);
24492457
#endif
24502458
}
24512459
else

0 commit comments

Comments
 (0)