Skip to content
Permalink
Browse files
Fix QgsDateTimeStatisticalSummary handling of non-datetime values
  • Loading branch information
nyalldawson committed Nov 30, 2016
1 parent 08505b3 commit 6a457c21cc8686034b0909db5e5265fd2e960e79
Showing with 15 additions and 3 deletions.
  1. +5 −0 src/core/qgsdatetimestatisticalsummary.cpp
  2. +10 −3 tests/src/python/test_qgsdatetimestatisticalsummary.py
@@ -66,6 +66,11 @@ void QgsDateTimeStatisticalSummary::addValue( const QVariant& value )
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else //not a date
{
mCountMissing++;
mCount++;
}
// QTime?
}

@@ -15,7 +15,8 @@
import qgis # NOQA

from qgis.core import (QgsDateTimeStatisticalSummary,
QgsInterval
QgsInterval,
NULL
)
from qgis.PyQt.QtCore import QDateTime, QDate, QTime
from qgis.testing import unittest
@@ -122,13 +123,13 @@ def testVariantStats(self):
QDateTime(QDate(1998, 1, 2), QTime(1, 10, 54)),
QDateTime(),
QDateTime(QDate(2011, 1, 5), QTime(11, 10, 54))])
self.assertEqual(s.count(), 7)
self.assertEqual(s.count(), 9)
self.assertEqual(set(s.distinctValues()), set([QDateTime(QDate(2015, 3, 4), QTime(11, 10, 54)),
QDateTime(QDate(2019, 12, 28), QTime(23, 10, 1)),
QDateTime(QDate(1998, 1, 2), QTime(1, 10, 54)),
QDateTime(QDate(2011, 1, 5), QTime(11, 10, 54)),
QDateTime()]))
self.assertEqual(s.countMissing(), 2)
self.assertEqual(s.countMissing(), 4)
self.assertEqual(s.min(), QDateTime(QDate(1998, 1, 2), QTime(1, 10, 54)))
self.assertEqual(s.max(), QDateTime(QDate(2019, 12, 28), QTime(23, 10, 1)))
self.assertEqual(s.range(), QgsInterval(693871147))
@@ -156,6 +157,12 @@ def testDates(self):
self.assertEqual(s.max(), QDateTime(QDate(2019, 12, 28), QTime()))
self.assertEqual(s.range(), QgsInterval(693792000))

def testMissing(self):
s = QgsDateTimeStatisticalSummary()
s.calculate([NULL,
'not a date'])
self.assertEqual(s.countMissing(), 2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 6a457c2

Please sign in to comment.