mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Fix some issues with to_interval expression function
- incorrect regex for handling values with decimal point - fix overflow with large intervals
This commit is contained in:
parent
d908518c49
commit
e02ff050ad
@ -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 @@ class TestQgsInterval(unittest.TestCase):
|
||||
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 @@ class TestQgsInterval(unittest.TestCase):
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user