8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.110 2003/08/04 02:40:04 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.111 2003/08/05 17:39:19 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1147,7 +1147,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
1147
1147
if (* cp != '\0' )
1148
1148
return -1 ;
1149
1149
#ifdef HAVE_INT64_TIMESTAMP
1150
- * fsec = frac * 1000000 ;
1150
+ * fsec = rint ( frac * 1000000 ) ;
1151
1151
#else
1152
1152
* fsec = frac ;
1153
1153
#endif
@@ -1177,9 +1177,11 @@ DecodeDateTime(char **field, int *ftype, int nf,
1177
1177
1178
1178
tmask |= DTK_TIME_M ;
1179
1179
#ifdef HAVE_INT64_TIMESTAMP
1180
- dt2time ((time * 86400000000 ), & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1180
+ dt2time ((time * 86400000000 ),
1181
+ & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1181
1182
#else
1182
- dt2time ((time * 86400 ), & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1183
+ dt2time ((time * 86400 ),
1184
+ & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1183
1185
#endif
1184
1186
}
1185
1187
break ;
@@ -1882,9 +1884,16 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
1882
1884
tmask = DTK_M (SECOND );
1883
1885
if (* cp == '.' )
1884
1886
{
1885
- * fsec = strtod (cp , & cp );
1887
+ double frac ;
1888
+
1889
+ frac = strtod (cp , & cp );
1886
1890
if (* cp != '\0' )
1887
1891
return -1 ;
1892
+ #ifdef HAVE_INT64_TIMESTAMP
1893
+ * fsec = rint (frac * 1000000 );
1894
+ #else
1895
+ * fsec = frac ;
1896
+ #endif
1888
1897
}
1889
1898
break ;
1890
1899
@@ -1910,9 +1919,11 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
1910
1919
1911
1920
tmask |= DTK_TIME_M ;
1912
1921
#ifdef HAVE_INT64_TIMESTAMP
1913
- dt2time ((time * 86400000000 ), & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1922
+ dt2time ((time * 86400000000 ),
1923
+ & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1914
1924
#else
1915
- dt2time ((time * 86400 ), & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1925
+ dt2time ((time * 86400 ),
1926
+ & tm -> tm_hour , & tm -> tm_min , & tm -> tm_sec , fsec );
1916
1927
#endif
1917
1928
}
1918
1929
break ;
@@ -2336,24 +2347,17 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
2336
2347
* fsec = 0 ;
2337
2348
else if (* cp == '.' )
2338
2349
{
2339
- #ifdef HAVE_INT64_TIMESTAMP
2340
- char fstr [MAXDATELEN + 1 ];
2350
+ double frac ;
2341
2351
2342
- /*
2343
- * OK, we have at most six digits to work with. Let's
2344
- * construct a string and then do the conversion to an
2345
- * integer.
2346
- */
2347
- strncpy (fstr , (cp + 1 ), 7 );
2348
- strcpy ((fstr + strlen (fstr )), "000000" );
2349
- * (fstr + 6 ) = '\0' ;
2350
- * fsec = strtol (fstr , & cp , 10 );
2351
- #else
2352
2352
str = cp ;
2353
- * fsec = strtod (str , & cp );
2354
- #endif
2353
+ frac = strtod (str , & cp );
2355
2354
if (* cp != '\0' )
2356
2355
return -1 ;
2356
+ #ifdef HAVE_INT64_TIMESTAMP
2357
+ * fsec = rint (frac * 1000000 );
2358
+ #else
2359
+ * fsec = frac ;
2360
+ #endif
2357
2361
}
2358
2362
else
2359
2363
return -1 ;
@@ -2396,6 +2400,8 @@ DecodeNumber(int flen, char *str, int fmask,
2396
2400
2397
2401
if (* cp == '.' )
2398
2402
{
2403
+ double frac ;
2404
+
2399
2405
/*
2400
2406
* More than two digits before decimal point? Then could be a date
2401
2407
* or a run-together time: 2001.360 20011225 040506.789
@@ -2404,9 +2410,14 @@ DecodeNumber(int flen, char *str, int fmask,
2404
2410
return DecodeNumberField (flen , str , (fmask | DTK_DATE_M ),
2405
2411
tmask , tm , fsec , is2digits );
2406
2412
2407
- * fsec = strtod (cp , & cp );
2413
+ frac = strtod (cp , & cp );
2408
2414
if (* cp != '\0' )
2409
2415
return -1 ;
2416
+ #ifdef HAVE_INT64_TIMESTAMP
2417
+ * fsec = rint (frac * 1000000 );
2418
+ #else
2419
+ * fsec = frac ;
2420
+ #endif
2410
2421
}
2411
2422
else if (* cp != '\0' )
2412
2423
return -1 ;
@@ -2514,19 +2525,13 @@ DecodeNumberField(int len, char *str, int fmask,
2514
2525
*/
2515
2526
if ((cp = strchr (str , '.' )) != NULL )
2516
2527
{
2517
- #ifdef HAVE_INT64_TIMESTAMP
2518
- char fstr [MAXDATELEN + 1 ];
2528
+ double frac ;
2519
2529
2520
- /*
2521
- * OK, we have at most six digits to care about. Let's construct a
2522
- * string and then do the conversion to an integer.
2523
- */
2524
- strcpy (fstr , (cp + 1 ));
2525
- strcpy ((fstr + strlen (fstr )), "000000" );
2526
- * (fstr + 6 ) = '\0' ;
2527
- * fsec = strtol (fstr , NULL , 10 );
2530
+ frac = strtod (cp , NULL );
2531
+ #ifdef HAVE_INT64_TIMESTAMP
2532
+ * fsec = rint (frac * 1000000 );
2528
2533
#else
2529
- * fsec = strtod ( cp , NULL ) ;
2534
+ * fsec = frac ;
2530
2535
#endif
2531
2536
* cp = '\0' ;
2532
2537
len = strlen (str );
0 commit comments