Skip to content

Commit

Permalink
Fix some issues with to_interval expression function
Browse files Browse the repository at this point in the history
- 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 e02ff05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsinterval.cpp
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions tests/src/python/test_qgsinterval.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e02ff05

Please sign in to comment.