88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -3044,7 +3044,8 @@ timestamp_age(PG_FUNCTION_ARGS)
30443044if (timestamp2tm (dt1 ,NULL ,tm1 ,& fsec1 ,NULL ,NULL )== 0 &&
30453045timestamp2tm (dt2 ,NULL ,tm2 ,& fsec2 ,NULL ,NULL )== 0 )
30463046{
3047- fsec = (fsec1 - fsec2 );
3047+ /* form the symbolic difference */
3048+ fsec = fsec1 - fsec2 ;
30483049tm -> tm_sec = tm1 -> tm_sec - tm2 -> tm_sec ;
30493050tm -> tm_min = tm1 -> tm_min - tm2 -> tm_min ;
30503051tm -> tm_hour = tm1 -> tm_hour - tm2 -> tm_hour ;
@@ -3064,6 +3065,17 @@ timestamp_age(PG_FUNCTION_ARGS)
30643065tm -> tm_year = - tm -> tm_year ;
30653066}
30663067
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+
30673079while (tm -> tm_sec < 0 )
30683080{
30693081tm -> tm_sec += SECS_PER_MINUTE ;
@@ -3158,6 +3170,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
31583170if (timestamp2tm (dt1 ,& tz1 ,tm1 ,& fsec1 ,& tzn ,NULL )== 0 &&
31593171timestamp2tm (dt2 ,& tz2 ,tm2 ,& fsec2 ,& tzn ,NULL )== 0 )
31603172{
3173+ /* form the symbolic difference */
31613174fsec = fsec1 - fsec2 ;
31623175tm -> tm_sec = tm1 -> tm_sec - tm2 -> tm_sec ;
31633176tm -> tm_min = tm1 -> tm_min - tm2 -> tm_min ;
@@ -3178,6 +3191,17 @@ timestamptz_age(PG_FUNCTION_ARGS)
31783191tm -> tm_year = - tm -> tm_year ;
31793192}
31803193
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+
31813205while (tm -> tm_sec < 0 )
31823206{
31833207tm -> tm_sec += SECS_PER_MINUTE ;