Skip to content

Commit

Permalink
Allow age expression to represent time intervals above 130 years (#5914)
Browse files Browse the repository at this point in the history
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 336995d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -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 ) );
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 336995d

Please sign in to comment.