8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.115 2004/11/20 22:12:44 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.116 2004/12/01 19:57:49 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
17
17
18
18
#include <ctype.h>
19
19
#include <math.h>
20
- #include <errno.h>
21
20
#include <float.h>
22
21
#include <limits.h>
23
22
@@ -2352,25 +2351,25 @@ timestamp_age(PG_FUNCTION_ARGS)
2352
2351
tm -> tm_year = - tm -> tm_year ;
2353
2352
}
2354
2353
2355
- if (tm -> tm_sec < 0 )
2354
+ while (tm -> tm_sec < 0 )
2356
2355
{
2357
2356
tm -> tm_sec += 60 ;
2358
2357
tm -> tm_min -- ;
2359
2358
}
2360
2359
2361
- if (tm -> tm_min < 0 )
2360
+ while (tm -> tm_min < 0 )
2362
2361
{
2363
2362
tm -> tm_min += 60 ;
2364
2363
tm -> tm_hour -- ;
2365
2364
}
2366
2365
2367
- if (tm -> tm_hour < 0 )
2366
+ while (tm -> tm_hour < 0 )
2368
2367
{
2369
2368
tm -> tm_hour += 24 ;
2370
2369
tm -> tm_mday -- ;
2371
2370
}
2372
2371
2373
- if (tm -> tm_mday < 0 )
2372
+ while (tm -> tm_mday < 0 )
2374
2373
{
2375
2374
if (dt1 < dt2 )
2376
2375
{
@@ -2384,7 +2383,7 @@ timestamp_age(PG_FUNCTION_ARGS)
2384
2383
}
2385
2384
}
2386
2385
2387
- if (tm -> tm_mon < 0 )
2386
+ while (tm -> tm_mon < 0 )
2388
2387
{
2389
2388
tm -> tm_mon += 12 ;
2390
2389
tm -> tm_year -- ;
@@ -2437,11 +2436,14 @@ timestamptz_age(PG_FUNCTION_ARGS)
2437
2436
* tm1 = & tt1 ;
2438
2437
struct pg_tm tt2 ,
2439
2438
* tm2 = & tt2 ;
2439
+ int tz1 ;
2440
+ int tz2 ;
2441
+ char * tzn ;
2440
2442
2441
2443
result = (Interval * ) palloc (sizeof (Interval ));
2442
2444
2443
- if ((timestamp2tm (dt1 , NULL , tm1 , & fsec1 , NULL ) == 0 )
2444
- && (timestamp2tm (dt2 , NULL , tm2 , & fsec2 , NULL ) == 0 ))
2445
+ if ((timestamp2tm (dt1 , & tz1 , tm1 , & fsec1 , & tzn ) == 0 )
2446
+ && (timestamp2tm (dt2 , & tz2 , tm2 , & fsec2 , & tzn ) == 0 ))
2445
2447
{
2446
2448
fsec = (fsec1 - fsec2 );
2447
2449
tm -> tm_sec = (tm1 -> tm_sec - tm2 -> tm_sec );
@@ -2463,25 +2465,25 @@ timestamptz_age(PG_FUNCTION_ARGS)
2463
2465
tm -> tm_year = - tm -> tm_year ;
2464
2466
}
2465
2467
2466
- if (tm -> tm_sec < 0 )
2468
+ while (tm -> tm_sec < 0 )
2467
2469
{
2468
2470
tm -> tm_sec += 60 ;
2469
2471
tm -> tm_min -- ;
2470
2472
}
2471
2473
2472
- if (tm -> tm_min < 0 )
2474
+ while (tm -> tm_min < 0 )
2473
2475
{
2474
2476
tm -> tm_min += 60 ;
2475
2477
tm -> tm_hour -- ;
2476
2478
}
2477
2479
2478
- if (tm -> tm_hour < 0 )
2480
+ while (tm -> tm_hour < 0 )
2479
2481
{
2480
2482
tm -> tm_hour += 24 ;
2481
2483
tm -> tm_mday -- ;
2482
2484
}
2483
2485
2484
- if (tm -> tm_mday < 0 )
2486
+ while (tm -> tm_mday < 0 )
2485
2487
{
2486
2488
if (dt1 < dt2 )
2487
2489
{
@@ -2495,12 +2497,16 @@ timestamptz_age(PG_FUNCTION_ARGS)
2495
2497
}
2496
2498
}
2497
2499
2498
- if (tm -> tm_mon < 0 )
2500
+ while (tm -> tm_mon < 0 )
2499
2501
{
2500
2502
tm -> tm_mon += 12 ;
2501
2503
tm -> tm_year -- ;
2502
2504
}
2503
2505
2506
+ /*
2507
+ * Note: we deliberately ignore any difference between tz1 and tz2.
2508
+ */
2509
+
2504
2510
/* recover sign if necessary... */
2505
2511
if (dt1 < dt2 )
2506
2512
{
0 commit comments