8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -3884,17 +3884,25 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
3884
3884
/* fractional seconds? */
3885
3885
if (fsec != 0 )
3886
3886
{
3887
+ fsec_t sec ;
3888
+
3887
3889
#ifdef HAVE_INT64_TIMESTAMP
3890
+ sec = fsec ;
3888
3891
if (is_before || ((!is_nonzero )&& (tm -> tm_sec < 0 )))
3892
+ {
3889
3893
tm -> 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
+ }
3890
3902
sprintf (cp ,"%s%d.%02d secs" , (is_nonzero ?" " :"" ),
3891
- tm -> tm_sec , (((int )fsec ) /10000 ));
3903
+ tm -> tm_sec , (((int )sec ) /10000 ));
3892
3904
cp += strlen (cp );
3893
- if (!is_nonzero )
3894
- is_before = (fsec < 0 );
3895
3905
#else
3896
- fsec_t sec ;
3897
-
3898
3906
fsec += tm -> tm_sec ;
3899
3907
sec = fsec ;
3900
3908
if (is_before || ((!is_nonzero )&& (fsec < 0 )))
@@ -3906,9 +3914,8 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
3906
3914
is_before = (fsec < 0 );
3907
3915
#endif
3908
3916
is_nonzero = TRUE;
3909
-
3910
- /* otherwise, integer seconds only? */
3911
3917
}
3918
+ /* otherwise, integer seconds only? */
3912
3919
else if (tm -> tm_sec != 0 )
3913
3920
{
3914
3921
int sec = tm -> tm_sec ;