88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.138 2005/04/19 03:13:59 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.139 2005/04/20 17:14:50 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -3884,17 +3884,25 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
38843884/* fractional seconds? */
38853885if (fsec != 0 )
38863886{
3887+ fsec_t sec ;
3888+
38873889#ifdef HAVE_INT64_TIMESTAMP
3890+ sec = fsec ;
38883891if (is_before || ((!is_nonzero )&& (tm -> tm_sec < 0 )))
3892+ {
38893893tm -> tm_sec = - tm -> tm_sec ;
3894+ sec = - sec ;
3895+ is_before = TRUE;
3896+ }
3897+ else if ((!is_nonzero )&& (tm -> tm_sec == 0 )&& (fsec < 0 ))
3898+ {
3899+ sec = - sec ;
3900+ is_before = TRUE;
3901+ }
38903902sprintf (cp ,"%s%d.%02d secs" , (is_nonzero ?" " :"" ),
3891- tm -> tm_sec , (((int )fsec ) /10000 ));
3903+ tm -> tm_sec , (((int )sec ) /10000 ));
38923904cp += strlen (cp );
3893- if (!is_nonzero )
3894- is_before = (fsec < 0 );
38953905#else
3896- fsec_t sec ;
3897-
38983906fsec += tm -> tm_sec ;
38993907sec = fsec ;
39003908if (is_before || ((!is_nonzero )&& (fsec < 0 )))
@@ -3906,9 +3914,8 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
39063914is_before = (fsec < 0 );
39073915#endif
39083916is_nonzero = TRUE;
3909-
3910- /* otherwise, integer seconds only? */
39113917}
3918+ /* otherwise, integer seconds only? */
39123919else if (tm -> tm_sec != 0 )
39133920{
39143921int sec = tm -> tm_sec ;