Skip to content

Commit

Permalink
#44160 add millisecond support to OGRUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Joonalai authored and nyalldawson committed Sep 17, 2021
1 parent 606bd09 commit 0a3526f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/qgsogrutils.cpp
Expand Up @@ -339,15 +339,20 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
case QVariant::DateTime:
case QVariant::Time:
{
int year, month, day, hour, minute, second, tzf;
int year, month, day, hour, minute, tzf;
float second;
float secondsPart = 0;

OGR_F_GetFieldAsDateTimeEx( ogrFet, attIndex, &year, &month, &day, &hour, &minute, &second, &tzf );
float millisecondPart = std::modf( second, &secondsPart );

OGR_F_GetFieldAsDateTime( ogrFet, attIndex, &year, &month, &day, &hour, &minute, &second, &tzf );
if ( field.type() == QVariant::Date )
value = QDate( year, month, day );
else if ( field.type() == QVariant::Time )
value = QTime( hour, minute, second );
value = QTime( hour, minute, static_cast< int >( secondsPart ), static_cast< int >( 1000 * millisecondPart ) );
else
value = QDateTime( QDate( year, month, day ), QTime( hour, minute, second ) );
value = QDateTime( QDate( year, month, day ),
QTime( hour, minute, static_cast< int >( secondsPart ), static_cast< int >( 1000 * millisecondPart ) ) );
}
break;

Expand Down

0 comments on commit 0a3526f

Please sign in to comment.