*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.110 2003/08/04 02:40:04 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.111 2003/08/05 17:39:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (*cp != '\0')
return -1;
#ifdef HAVE_INT64_TIMESTAMP
- *fsec = frac * 1000000;
+ *fsec = rint(frac * 1000000);
#else
*fsec = frac;
#endif
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
- dt2time((time * 86400000000), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+ dt2time((time * 86400000000),
+ &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#else
- dt2time((time * 86400), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+ dt2time((time * 86400),
+ &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#endif
}
break;
tmask = DTK_M(SECOND);
if (*cp == '.')
{
- *fsec = strtod(cp, &cp);
+ double frac;
+
+ frac = strtod(cp, &cp);
if (*cp != '\0')
return -1;
+#ifdef HAVE_INT64_TIMESTAMP
+ *fsec = rint(frac * 1000000);
+#else
+ *fsec = frac;
+#endif
}
break;
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
- dt2time((time * 86400000000), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+ dt2time((time * 86400000000),
+ &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#else
- dt2time((time * 86400), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+ dt2time((time * 86400),
+ &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#endif
}
break;
*fsec = 0;
else if (*cp == '.')
{
-#ifdef HAVE_INT64_TIMESTAMP
- char fstr[MAXDATELEN + 1];
+ double frac;
- /*
- * OK, we have at most six digits to work with. Let's
- * construct a string and then do the conversion to an
- * integer.
- */
- strncpy(fstr, (cp + 1), 7);
- strcpy((fstr + strlen(fstr)), "000000");
- *(fstr + 6) = '\0';
- *fsec = strtol(fstr, &cp, 10);
-#else
str = cp;
- *fsec = strtod(str, &cp);
-#endif
+ frac = strtod(str, &cp);
if (*cp != '\0')
return -1;
+#ifdef HAVE_INT64_TIMESTAMP
+ *fsec = rint(frac * 1000000);
+#else
+ *fsec = frac;
+#endif
}
else
return -1;
if (*cp == '.')
{
+ double frac;
+
/*
* More than two digits before decimal point? Then could be a date
* or a run-together time: 2001.360 20011225 040506.789
return DecodeNumberField(flen, str, (fmask | DTK_DATE_M),
tmask, tm, fsec, is2digits);
- *fsec = strtod(cp, &cp);
+ frac = strtod(cp, &cp);
if (*cp != '\0')
return -1;
+#ifdef HAVE_INT64_TIMESTAMP
+ *fsec = rint(frac * 1000000);
+#else
+ *fsec = frac;
+#endif
}
else if (*cp != '\0')
return -1;
*/
if ((cp = strchr(str, '.')) != NULL)
{
-#ifdef HAVE_INT64_TIMESTAMP
- char fstr[MAXDATELEN + 1];
+ double frac;
- /*
- * OK, we have at most six digits to care about. Let's construct a
- * string and then do the conversion to an integer.
- */
- strcpy(fstr, (cp + 1));
- strcpy((fstr + strlen(fstr)), "000000");
- *(fstr + 6) = '\0';
- *fsec = strtol(fstr, NULL, 10);
+ frac = strtod(cp, NULL);
+#ifdef HAVE_INT64_TIMESTAMP
+ *fsec = rint(frac * 1000000);
#else
- *fsec = strtod(cp, NULL);
+ *fsec = frac;
#endif
*cp = '\0';
len = strlen(str);