diff --git a/reference/unicsv_subsec.csv b/reference/unicsv_subsec.csv index f2db505a8..aea79965e 100644 --- a/reference/unicsv_subsec.csv +++ b/reference/unicsv_subsec.csv @@ -10,3 +10,14 @@ No,Latitude,Longitude,Name,Date,Time 9,33.784805,-117.474327,"WPT009",2014/09/17,13:20:22 10,33.784805,-117.474327,"WPT010",2014/09/17,13:20:22.200 11,33.784805,-117.474327,"WPT011",2014/09/17,13:20:22.400 +12,33.784805,-117.474327,"WPT012",2014/09/17,13:20:23.699 +13,33.784805,-117.474327,"WPT013",2014/09/17,13:20:23.69 +14,33.784805,-117.474327,"WPT014",2014/09/17,13:20:23.6 +15,33.784805,-117.474327,"WPT015",2014/09/17,13:20:23 +16,33.784805,-117.474327,"WPT016",2014/09/17,13:20:23. +17,33.784805,-117.474327,"WPT017",2014/09/17,13:20:23.69 +18,33.784805,-117.474327,"WPT018",2014/09/17,13:20:23.699 +19,33.784805,-117.474327,"WPT019",2014/09/17,13:20:23.6999 +20,33.784805,-117.474327,"WPT020",2014/09/17,13:20:23.69999 +21,33.784805,-117.474327,"WPT021",2014/09/17,13:20:23.699999 +22,33.784805,-117.474327,"WPT022",2014/09/17,13:20:23.6999999 diff --git a/reference/unicsv_subsec~csv.csv b/reference/unicsv_subsec~csv.csv new file mode 100644 index 000000000..186f2dc9f --- /dev/null +++ b/reference/unicsv_subsec~csv.csv @@ -0,0 +1,23 @@ +No,Latitude,Longitude,Name,Date,Time +1,33.784801,-117.474350,"WPT001",2014/09/17,13:20:20.004 +2,33.784801,-117.474342,"WPT002",2014/09/17,13:20:20.060 +3,33.784801,-117.474342,"WPT003",2014/09/17,13:20:20.800 +4,33.784801,-117.474342,"WPT004",2014/09/17,13:20:21 +5,33.784801,-117.474342,"WPT005",2014/09/17,13:20:21.200 +6,33.784801,-117.474335,"WPT006",2014/09/17,13:20:21.400 +7,33.784801,-117.474335,"WPT007",2014/09/17,13:20:21.600 +8,33.784801,-117.474335,"WPT008",2014/09/17,13:20:21.800 +9,33.784805,-117.474327,"WPT009",2014/09/17,13:20:22 +10,33.784805,-117.474327,"WPT010",2014/09/17,13:20:22.200 +11,33.784805,-117.474327,"WPT011",2014/09/17,13:20:22.400 +12,33.784805,-117.474327,"WPT012",2014/09/17,13:20:23.699 +13,33.784805,-117.474327,"WPT013",2014/09/17,13:20:23.690 +14,33.784805,-117.474327,"WPT014",2014/09/17,13:20:23.600 +15,33.784805,-117.474327,"WPT015",2014/09/17,13:20:23 +16,33.784805,-117.474327,"WPT016",2014/09/17,13:20:23 +17,33.784805,-117.474327,"WPT017",2014/09/17,13:20:23.690 +18,33.784805,-117.474327,"WPT018",2014/09/17,13:20:23.699 +19,33.784805,-117.474327,"WPT019",2014/09/17,13:20:23.699 +20,33.784805,-117.474327,"WPT020",2014/09/17,13:20:23.699 +21,33.784805,-117.474327,"WPT021",2014/09/17,13:20:23.699 +22,33.784805,-117.474327,"WPT022",2014/09/17,13:20:23.699 diff --git a/testo.d/unicsv.test b/testo.d/unicsv.test index 6c31bba94..05429876e 100644 --- a/testo.d/unicsv.test +++ b/testo.d/unicsv.test @@ -28,7 +28,7 @@ compare ${TMPDIR}/unicsv_encoding.csv ${REFERENCE}/unicsv_encoding.csv # verify fractional second read and writes. gpsbabel -i unicsv -f ${REFERENCE}/unicsv_subsec.csv -o unicsv -F ${TMPDIR}/unicsv_subsec.csv -compare ${REFERENCE}/unicsv_subsec.csv ${TMPDIR}/unicsv_subsec.csv +compare ${REFERENCE}/unicsv_subsec~csv.csv ${TMPDIR}/unicsv_subsec.csv # Verify 'fields' option gpsbabel -i unicsv,fields=lat+lon+description -f ${REFERENCE}/radius.csv -o csv -F ${TMPDIR}/unicsv_fields.out diff --git a/unicsv.cc b/unicsv.cc index 92ca85043..ffbc2ffd8 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -287,7 +287,6 @@ UnicsvFormat::unicsv_parse_time(const char* str, QDate& date) int sec; int msec; int consumed = 0; - double frac_sec; /* If we have something we're pretty sure is a date, parse that * first, skip over it, and pass that back to the caller) @@ -297,14 +296,17 @@ UnicsvFormat::unicsv_parse_time(const char* str, QDate& date) str += consumed; date = ldate; } - int ct = sscanf(str, "%d%*1[.://]%d%*1[.://]%d%lf", &hour, &min, &sec, &frac_sec); + char msecstr[4]; + int ct = sscanf(str, "%d%*1[.://]%d%*1[.://]%d.%3[0123456789]", &hour, &min, &sec, msecstr); if (ct < 3) { fatal(FatalMsg() << MYNAME << ": Could not parse time string (" << str << ")."); } if (ct >= 4) { // Don't round up and ripple through seconds, minutes, hours. // 23:59:59.9999999 -> 24:00:00.000 which is an invalid QTime. - msec = frac_sec * 1000.0; + QByteArray msecba = msecstr; + msecba.append(3 - msecba.size(), '0'); // right pad to 3 digits. + msec = msecba.toInt(); } else { msec = 0; }