Skip to content
Permalink
Browse files

[DelimitedText provider] Avoid false positive detection of some date …

…looking content as Time (fixes #38091)
  • Loading branch information
rouault authored and nyalldawson committed Sep 14, 2020
1 parent c6fe79b commit cd04374d51433398758610549dcd944f4a697019
@@ -652,8 +652,26 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )

if ( couldBeTime[i] && !couldBeDateTime[i] )
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QTime t = QTime::fromString( value );
couldBeTime[i] = t.isValid();
#else
// Accept 12:34, 12:34:56 or 12:34:56.789
// We do not use QTime::fromString() with Qt < 5.14 as it accepts
// strings like 01/03/2004 as valid times
couldBeTime[i] = value.length() >= 5 &&
value[0] >= '0' && value[0] <= '2' &&
value[1] >= '0' && value[1] <= '9' &&
value[2] == ':' &&
value[3] >= '0' && value[3] <= '5' &&
value[4] >= '0' && value[4] <= '9' &&
( value.length() == 5 ||
( value.length() >= 8 && (
value[5] == ':' &&
value[6] >= '0' && value[6] <= '6' &&
value[7] >= '0' && value[7] <= '9' &&
( value.length() == 8 || value[8] == '.' ) ) ) );
#endif
}
}
}
@@ -926,6 +926,7 @@ def test_047_datetime(self):
assert vl.fields().at(4).type() == QVariant.DateTime
assert vl.fields().at(5).type() == QVariant.Date
assert vl.fields().at(6).type() == QVariant.Time
assert vl.fields().at(9).type() == QVariant.String

def testSpatialIndex(self):
srcpath = os.path.join(TEST_DATA_DIR, 'provider')
@@ -1,3 +1,9 @@
point_id,X,Y,ele,time,date,t,Ds,len
"371",676239.6644,212505.7907,486,2020/04/07 09:58:07,2020/04/07,09:58:07,0,0
"372",676238.6797,212497.3033,486.2,2020/04/07 09:58:08,2020/04/07,09:58:08,8.544,8.54
point_id,X,Y,ele,time,date,t,Ds,len,not_time
"371",676239.6644,212505.7907,486,2020/04/07 09:58:07,2020/04/07,09:58:07,0,0,01/03/2004
"372",676238.6797,212497.3033,486.2,2020/04/07 09:58:08,2020/04/07,09:58:08,8.544,8.54,01/03/2004
,,,,,,00:00,,,
,,,,,,00:00:00,,,
,,,,,,00:00:00.000,,,
,,,,,,23:59,,,
,,,,,,23:59:59,,,
,,,,,,23:59:59.999,,,
@@ -1 +1 @@
"Integer","Real","Real","Real","DateTime","Date","Time","Real","Real"
"Integer","Real","Real","Real","DateTime","Date","Time","Real","Real","String"

0 comments on commit cd04374

Please sign in to comment.
You can’t perform that action at this time.