8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.179 2007/07/06 04:15:59 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.180 2007/07/18 03:13:13 momjian Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -3044,7 +3044,8 @@ timestamp_age(PG_FUNCTION_ARGS)
3044
3044
if (timestamp2tm (dt1 , NULL , tm1 , & fsec1 , NULL , NULL ) == 0 &&
3045
3045
timestamp2tm (dt2 , NULL , tm2 , & fsec2 , NULL , NULL ) == 0 )
3046
3046
{
3047
- fsec = (fsec1 - fsec2 );
3047
+ /* form the symbolic difference */
3048
+ fsec = fsec1 - fsec2 ;
3048
3049
tm -> tm_sec = tm1 -> tm_sec - tm2 -> tm_sec ;
3049
3050
tm -> tm_min = tm1 -> tm_min - tm2 -> tm_min ;
3050
3051
tm -> tm_hour = tm1 -> tm_hour - tm2 -> tm_hour ;
@@ -3064,6 +3065,17 @@ timestamp_age(PG_FUNCTION_ARGS)
3064
3065
tm -> tm_year = - tm -> tm_year ;
3065
3066
}
3066
3067
3068
+ /* propagate any negative fields into the next higher field */
3069
+ while (fsec < 0 )
3070
+ {
3071
+ #ifdef HAVE_INT64_TIMESTAMP
3072
+ fsec += USECS_PER_SEC ;
3073
+ #else
3074
+ fsec += 1.0 ;
3075
+ #endif
3076
+ tm -> tm_sec -- ;
3077
+ }
3078
+
3067
3079
while (tm -> tm_sec < 0 )
3068
3080
{
3069
3081
tm -> tm_sec += SECS_PER_MINUTE ;
@@ -3158,6 +3170,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
3158
3170
if (timestamp2tm (dt1 , & tz1 , tm1 , & fsec1 , & tzn , NULL ) == 0 &&
3159
3171
timestamp2tm (dt2 , & tz2 , tm2 , & fsec2 , & tzn , NULL ) == 0 )
3160
3172
{
3173
+ /* form the symbolic difference */
3161
3174
fsec = fsec1 - fsec2 ;
3162
3175
tm -> tm_sec = tm1 -> tm_sec - tm2 -> tm_sec ;
3163
3176
tm -> tm_min = tm1 -> tm_min - tm2 -> tm_min ;
@@ -3178,6 +3191,17 @@ timestamptz_age(PG_FUNCTION_ARGS)
3178
3191
tm -> tm_year = - tm -> tm_year ;
3179
3192
}
3180
3193
3194
+ /* propagate any negative fields into the next higher field */
3195
+ while (fsec < 0 )
3196
+ {
3197
+ #ifdef HAVE_INT64_TIMESTAMP
3198
+ fsec += USECS_PER_SEC ;
3199
+ #else
3200
+ fsec += 1.0 ;
3201
+ #endif
3202
+ tm -> tm_sec -- ;
3203
+ }
3204
+
3181
3205
while (tm -> tm_sec < 0 )
3182
3206
{
3183
3207
tm -> tm_sec += SECS_PER_MINUTE ;
0 commit comments