Skip to content
Permalink
Browse files

Handle nulls for date/time correctly

(cherry picked from commit aa062f9)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 496b10b commit 69c1bdf7e0fed5f2752e90011ed96473598f84bd
Showing with 26 additions and 18 deletions.
  1. +26 −18 src/core/qgsdatetimestatisticalsummary.cpp
@@ -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?
}

0 comments on commit 69c1bdf

Please sign in to comment.