Changeset: ea92be832e7e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ea92be832e7e
Modified Files:
monetdb5/modules/atoms/mtime.c
Branch: Dec2016
Log Message:
Also round timestamp values unless TRUNCATE_NUMBERS is defined.
A timestamp value of '23:59:59.999999' is not rounded since the
resulting value wouldn't be valid.
Also see changeset 412cc3428d91.
diffs (47 lines):
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -687,12 +687,38 @@ daytime_fromstr(const char *buf, int *le
}
if ((buf[pos] == '.' || (synonyms && buf[pos] == ':')) &&
GDKisdigit(buf[pos + 1])) {
- int fac = 100;
-
- for (pos++, msec = 0; GDKisdigit(buf[pos]); pos++) {
- msec += (buf[pos] - '0') * fac;
- fac /= 10;
+ int i;
+ pos++;
+ for (i = 0; i < 3; i++) {
+ msec *= 10;
+ if (GDKisdigit(buf[pos])) {
+ msec += buf[pos] - '0';
+ pos++;
+ }
}
+#ifndef TRUNCATE_NUMBERS
+ if (GDKisdigit(buf[pos]) && buf[pos] >= '5') {
+ /* round the value */
+ if (++msec == 1000) {
+ msec = 0;
+ if (++sec == 60) {
+ sec = 0;
+ if (++min == 60) {
+ min = 0;
+ if (++hour == 24) {
+ /* forget about
rounding if it doesn't fit */
+ hour = 23;
+ min = 59;
+ sec = 59;
+ msec = 999;
+ }
+ }
+ }
+ }
+ }
+#endif
+ while (GDKisdigit(buf[pos]))
+ pos++;
}
}
/* handle semantic error here (returns nil in that case) */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list