Navigation Menu

Skip to content

Commit

Permalink
Handle nulls for date/time correctly
Browse files Browse the repository at this point in the history
(cherry picked from commit aa062f9)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 496b10b commit 69c1bdf
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/core/qgsdatetimestatisticalsummary.cpp
Expand Up @@ -58,28 +58,36 @@ void QgsDateTimeStatisticalSummary::calculate( const QVariantList &values )

void QgsDateTimeStatisticalSummary::addValue( const QVariant &value )
{
if ( value.type() == QVariant::DateTime )
{
testDateTime( value.toDateTime() );
}
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( ! date.isNull() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( ! time.isNull() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
}
else //not a date
if ( value.isNull() )
{
mCountMissing++;
mCount++;
}
else
{
if ( value.type() == QVariant::DateTime )
{
testDateTime( value.toDateTime() );
}
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
}
else //not a date
{
mCountMissing++;
mCount++;
}
}
// QTime?
}

Expand Down

0 comments on commit 69c1bdf

Please sign in to comment.