8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.58 2001/01/17 16:46:56 thomas Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.59 2001/01/18 07:22:35 thomas Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -880,11 +880,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
880
880
* tzp = - (tm -> tm_gmtoff ); /* tm_gmtoff is
881
881
* Sun/DEC-ism */
882
882
# elif defined(HAVE_INT_TIMEZONE )
883
- # ifdef __CYGWIN__
884
- * tzp = ((tm -> tm_isdst > 0 ) ? (_timezone - 3600 ) : _timezone );
885
- # else
886
- * tzp = ((tm -> tm_isdst > 0 ) ? (timezone - 3600 ) : timezone );
887
- # endif /* __CYGWIN__ */
883
+ * tzp = ((tm -> tm_isdst > 0 ) ? (TIMEZONE_GLOBAL - 3600 ) : TIMEZONE_GLOBAL );
888
884
# endif /* HAVE_INT_TIMEZONE */
889
885
890
886
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
@@ -1128,11 +1124,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
1128
1124
# if defined(HAVE_TM_ZONE )
1129
1125
* tzp = - (tmp -> tm_gmtoff ); /* tm_gmtoff is Sun/DEC-ism */
1130
1126
# elif defined(HAVE_INT_TIMEZONE )
1131
- # ifdef __CYGWIN__
1132
- * tzp = ((tmp -> tm_isdst > 0 ) ? (_timezone - 3600 ) : _timezone );
1133
- # else
1134
- * tzp = ((tmp -> tm_isdst > 0 ) ? (timezone - 3600 ) : timezone );
1135
- # endif
1127
+ * tzp = ((tmp -> tm_isdst > 0 ) ? (TIMEZONE_GLOBAL - 3600 ) : TIMEZONE_GLOBAL );
1136
1128
# endif
1137
1129
1138
1130
#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */
@@ -2252,12 +2244,14 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2252
2244
is_before = (tm -> tm_mday < 0 );
2253
2245
is_nonzero = TRUE;
2254
2246
}
2247
+ if ((!is_nonzero ) || (tm -> tm_hour != 0 ) || (tm -> tm_min != 0 )
2248
+ || (tm -> tm_sec != 0 ) || (fsec != 0 ))
2255
2249
{
2256
2250
int minus = ((tm -> tm_hour < 0 ) || (tm -> tm_min < 0 )
2257
2251
|| (tm -> tm_sec < 0 ) || (fsec < 0 ));
2258
2252
2259
2253
sprintf (cp , "%s%s%02d:%02d" , (is_nonzero ? " " : "" ),
2260
- (minus ? "-" : (is_nonzero ? "+" : "" )),
2254
+ (minus ? "-" : (is_before ? "+" : "" )),
2261
2255
abs (tm -> tm_hour ), abs (tm -> tm_min ));
2262
2256
cp += strlen (cp );
2263
2257
/* Mark as "non-zero" since the fields are now filled in */
@@ -2289,7 +2283,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2289
2283
2290
2284
if (tm -> tm_year != 0 )
2291
2285
{
2292
- int year = ((tm -> tm_year < 0 ) ? - (tm -> tm_year ) : tm -> tm_year );
2286
+ int year = tm -> tm_year ;
2287
+ if (tm -> tm_year < 0 )
2288
+ year = - year ;
2293
2289
2294
2290
sprintf (cp , "%d year%s" , year ,
2295
2291
((year != 1 ) ? "s" : "" ));
@@ -2300,7 +2296,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2300
2296
2301
2297
if (tm -> tm_mon != 0 )
2302
2298
{
2303
- int mon = ((is_before && (tm -> tm_mon > 0 )) ? - (tm -> tm_mon ) : tm -> tm_mon );
2299
+ int mon = tm -> tm_mon ;
2300
+ if (is_before || ((!is_nonzero ) && (tm -> tm_mon < 0 )))
2301
+ mon = - mon ;
2304
2302
2305
2303
sprintf (cp , "%s%d mon%s" , (is_nonzero ? " " : "" ), mon ,
2306
2304
((mon != 1 ) ? "s" : "" ));
@@ -2312,7 +2310,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2312
2310
2313
2311
if (tm -> tm_mday != 0 )
2314
2312
{
2315
- int day = ((is_before && (tm -> tm_mday > 0 )) ? - (tm -> tm_mday ) : tm -> tm_mday );
2313
+ int day = tm -> tm_mday ;
2314
+ if (is_before || ((!is_nonzero ) && (tm -> tm_mday < 0 )))
2315
+ day = - day ;
2316
2316
2317
2317
sprintf (cp , "%s%d day%s" , (is_nonzero ? " " : "" ), day ,
2318
2318
((day != 1 ) ? "s" : "" ));
@@ -2323,7 +2323,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2323
2323
}
2324
2324
if (tm -> tm_hour != 0 )
2325
2325
{
2326
- int hour = ((is_before && (tm -> tm_hour > 0 )) ? - (tm -> tm_hour ) : tm -> tm_hour );
2326
+ int hour = tm -> tm_hour ;
2327
+ if (is_before || ((!is_nonzero ) && (tm -> tm_hour < 0 )))
2328
+ hour = - hour ;
2327
2329
2328
2330
sprintf (cp , "%s%d hour%s" , (is_nonzero ? " " : "" ), hour ,
2329
2331
((hour != 1 ) ? "s" : "" ));
@@ -2335,7 +2337,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2335
2337
2336
2338
if (tm -> tm_min != 0 )
2337
2339
{
2338
- int min = ((is_before && (tm -> tm_min > 0 )) ? - (tm -> tm_min ) : tm -> tm_min );
2340
+ int min = tm -> tm_min ;
2341
+ if (is_before || ((!is_nonzero ) && (tm -> tm_min < 0 )))
2342
+ min = - min ;
2339
2343
2340
2344
sprintf (cp , "%s%d min%s" , (is_nonzero ? " " : "" ), min ,
2341
2345
((min != 1 ) ? "s" : "" ));
@@ -2348,9 +2352,13 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2348
2352
/* fractional seconds? */
2349
2353
if (fsec != 0 )
2350
2354
{
2355
+ double sec ;
2351
2356
fsec += tm -> tm_sec ;
2352
- sprintf (cp , "%s%.2f secs" , (is_nonzero ? " " : "" ),
2353
- ((is_before && (fsec > 0 )) ? - (fsec ) : fsec ));
2357
+ sec = fsec ;
2358
+ if (is_before || ((!is_nonzero ) && (fsec < 0 )))
2359
+ sec = - sec ;
2360
+
2361
+ sprintf (cp , "%s%.2f secs" , (is_nonzero ? " " : "" ), sec );
2354
2362
cp += strlen (cp );
2355
2363
if (! is_nonzero )
2356
2364
is_before = (fsec < 0 );
@@ -2360,7 +2368,9 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
2360
2368
}
2361
2369
else if (tm -> tm_sec != 0 )
2362
2370
{
2363
- int sec = ((is_before && (tm -> tm_sec > 0 )) ? - (tm -> tm_sec ) : tm -> tm_sec );
2371
+ int sec = tm -> tm_sec ;
2372
+ if (is_before || ((!is_nonzero ) && (tm -> tm_sec < 0 )))
2373
+ sec = - sec ;
2364
2374
2365
2375
sprintf (cp , "%s%d sec%s" , (is_nonzero ? " " : "" ), sec ,
2366
2376
((sec != 1 ) ? "s" : "" ));
0 commit comments