How to find the source code used for a function in the latest QGIS Field calculator


I am having difficulty understanding how QGIS calculates the difference between two dates with the "AGE" function and would like to see how it is coded.

If this is possible, how do I find the source?

Best Answer

It is available here. We see it is computed as the number of seconds between the two inputs.

static QVariant fcnAge( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
  QDateTime d1 = QgsExpressionUtils::getDateTimeValue( 0 ), parent );
  QDateTime d2 = QgsExpressionUtils::getDateTimeValue( 1 ), parent );
  qint64 seconds = d2.secsTo( d1 );
  return QVariant::fromValue( QgsInterval( seconds ) );