Skip to content
Permalink
Browse files

Allow age expression to represent time intervals above 130 years (#5914)

Uses a 64bit integer instead of 32bit one for seconds,
meaning about 584 billions of years rather than 136...

Closes #17681

Includes test
  • Loading branch information
strk committed Dec 19, 2017
1 parent cefae89 commit 336995dc30f4409520b65a0007e2cea6966f7599
Showing with 2 additions and 1 deletion.
  1. +1 −1 src/core/expression/qgsexpressionfunction.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -1425,7 +1425,7 @@ static QVariant fcnAge( const QVariantList &values, const QgsExpressionContext *
{
QDateTime d1 = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
QDateTime d2 = QgsExpressionUtils::getDateTimeValue( values.at( 1 ), parent );
int seconds = d2.secsTo( d1 );
qint64 seconds = d2.secsTo( d1 );
return QVariant::fromValue( QgsInterval( seconds ) );
}

@@ -1045,6 +1045,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "year with interval" ) << "year(tointerval('2 years'))" << false << QVariant( 2.0 );
QTest::newRow( "age" ) << "age('2012-06-30','2012-06-28')" << false << QVariant::fromValue( QgsInterval( 172800 ) );
QTest::newRow( "negative age" ) << "age('2012-06-28','2012-06-30')" << false << QVariant::fromValue( QgsInterval( -172800 ) );
QTest::newRow( "big age" ) << "age('2000-01-01','1000-01-01')" << false << QVariant::fromValue( QgsInterval( 31556908800LL ) );
QTest::newRow( "day of week date" ) << "day_of_week(todate('2015-09-21'))" << false << QVariant( 1 );
QTest::newRow( "day of week datetime" ) << "day_of_week(to_datetime('2015-09-20 13:01:43'))" << false << QVariant( 0 );
QTest::newRow( "hour datetime" ) << "hour(to_datetime('2015-09-20 13:01:43'))" << false << QVariant( 13 );

0 comments on commit 336995d

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