Skip to content
Permalink
Browse files

Fix some issues with to_interval expression function

- incorrect regex for handling values with decimal point
- fix overflow with large intervals
  • Loading branch information
nyalldawson committed Dec 21, 2017
1 parent d908518 commit e02ff050ad2188470e68fdef7b86270995a8d246
Showing with 8 additions and 2 deletions.
  1. +2 −2 src/core/qgsinterval.cpp
  2. +6 −0 tests/src/python/test_qgsinterval.py
@@ -44,8 +44,8 @@ bool QgsInterval::operator==( QgsInterval other ) const

QgsInterval QgsInterval::fromString( const QString &string )
{
int seconds = 0;
QRegExp rx( "([-+]?\\d?\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
double seconds = 0;
QRegExp rx( "([-+]?\\d*\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
QStringList list;
int pos = 0;

@@ -118,6 +118,9 @@ def testFromString(self):
i = QgsInterval.fromString('2 Years')
self.assertTrue(i.isValid())
self.assertEqual(i.years(), 2)
i = QgsInterval.fromString('20000 Years')
self.assertTrue(i.isValid())
self.assertEqual(i.years(), 20000)
i = QgsInterval.fromString('30 month')
self.assertTrue(i.isValid())
self.assertEqual(i.months(), 30)
@@ -133,6 +136,9 @@ def testFromString(self):
i = QgsInterval.fromString('1 Day')
self.assertTrue(i.isValid())
self.assertEqual(i.seconds(), 24 * 60 * 60)
i = QgsInterval.fromString('101.5 Days')
self.assertTrue(i.isValid())
self.assertEqual(i.seconds(), 101.5 * 24 * 60 * 60)
i = QgsInterval.fromString('2 dAys')
self.assertTrue(i.isValid())
self.assertEqual(i.seconds(), 48 * 60 * 60)

0 comments on commit e02ff05

Please sign in to comment.
You can’t perform that action at this time.