Skip to content

Commit

Permalink
Fix AFS datetime value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 14, 2020
1 parent e82aa17 commit 72a9ef5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -54,7 +54,7 @@ QVariant::Type QgsArcGisRestUtils::mapEsriFieldType( const QString &esriFieldTyp
if ( esriFieldType == QLatin1String( "esriFieldTypeString" ) )
return QVariant::String;
if ( esriFieldType == QLatin1String( "esriFieldTypeDate" ) )
return QVariant::Date;
return QVariant::DateTime;
if ( esriFieldType == QLatin1String( "esriFieldTypeGeometry" ) )
return QVariant::Invalid; // Geometry column should not appear as field
if ( esriFieldType == QLatin1String( "esriFieldTypeOID" ) )
Expand Down Expand Up @@ -1070,7 +1070,7 @@ QDateTime QgsArcGisRestUtils::parseDateTime( const QVariant &value )
if ( value.isNull() )
return QDateTime();
bool ok = false;
QDateTime dt = QDateTime::fromMSecsSinceEpoch( value.toLongLong( &ok ), Qt::UTC );
QDateTime dt = QDateTime::fromMSecsSinceEpoch( value.toLongLong( &ok ) );
if ( !ok )
{
QgsDebugMsg( QStringLiteral( "Invalid value %1 for datetime" ).arg( value.toString() ) );
Expand Down
8 changes: 7 additions & 1 deletion tests/src/python/test_provider_afs.py
Expand Up @@ -244,6 +244,9 @@ def setUpClass(cls):
{"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null},
{"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null},
{"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null},
{"name":"dt","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"date","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"time","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}],
"features": [
{
Expand Down Expand Up @@ -336,6 +339,9 @@ def setUpClass(cls):
{"name":"name","type":"esriFieldTypeString","alias":"name","length":100,"domain":null},
{"name":"name2","type":"esriFieldTypeString","alias":"name2","length":100,"domain":null},
{"name":"num_char","type":"esriFieldTypeString","alias":"num_char","length":100,"domain":null},
{"name":"dt","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"date","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"time","type":"esriFieldTypeDate","alias":"num_char","length":100,"domain":null},
{"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}],
"features": [
{
Expand Down Expand Up @@ -607,7 +613,7 @@ def testDateTime(self):

features = [f for f in vl.getFeatures()]
self.assertEqual(len(features), 2)
self.assertEqual([f['dt'] for f in features], [QDate(2017, 5, 3), NULL])
self.assertEqual([f['dt'] for f in features], [QDateTime(2017, 5, 3, 0, 0, 0, 0, Qt.UTC).toLocalTime(), NULL])

def testMetadata(self):
""" Test that metadata is correctly acquired from provider """
Expand Down

0 comments on commit 72a9ef5

Please sign in to comment.