@@ -1103,6 +1103,60 @@ static QVariant fcnToDateTime( const QVariantList &values, const QgsExpressionCo
1103
1103
return QVariant ( datetime );
1104
1104
}
1105
1105
1106
+ static QVariant fcnMakeDate ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
1107
+ {
1108
+ const int year = QgsExpressionUtils::getIntValue ( values.at ( 0 ), parent );
1109
+ const int month = QgsExpressionUtils::getIntValue ( values.at ( 1 ), parent );
1110
+ const int day = QgsExpressionUtils::getIntValue ( values.at ( 2 ), parent );
1111
+
1112
+ const QDate date ( year, month, day );
1113
+ if ( !date.isValid () )
1114
+ {
1115
+ parent->setEvalErrorString ( QObject::tr ( " '%1-%2-%3' is not a valid date" ).arg ( year ).arg ( month ).arg ( day ) );
1116
+ return QVariant ();
1117
+ }
1118
+ return QVariant ( date );
1119
+ }
1120
+
1121
+ static QVariant fcnMakeTime ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
1122
+ {
1123
+ const int hours = QgsExpressionUtils::getIntValue ( values.at ( 0 ), parent );
1124
+ const int minutes = QgsExpressionUtils::getIntValue ( values.at ( 1 ), parent );
1125
+ const double seconds = QgsExpressionUtils::getDoubleValue ( values.at ( 2 ), parent );
1126
+
1127
+ const QTime time ( hours, minutes, std::floor ( seconds ), ( seconds - std::floor ( seconds ) ) * 1000 );
1128
+ if ( !time.isValid () )
1129
+ {
1130
+ parent->setEvalErrorString ( QObject::tr ( " '%1-%2-%3' is not a valid time" ).arg ( hours ).arg ( minutes ).arg ( seconds ) );
1131
+ return QVariant ();
1132
+ }
1133
+ return QVariant ( time );
1134
+ }
1135
+
1136
+ static QVariant fcnMakeDateTime ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
1137
+ {
1138
+ const int year = QgsExpressionUtils::getIntValue ( values.at ( 0 ), parent );
1139
+ const int month = QgsExpressionUtils::getIntValue ( values.at ( 1 ), parent );
1140
+ const int day = QgsExpressionUtils::getIntValue ( values.at ( 2 ), parent );
1141
+ const int hours = QgsExpressionUtils::getIntValue ( values.at ( 3 ), parent );
1142
+ const int minutes = QgsExpressionUtils::getIntValue ( values.at ( 4 ), parent );
1143
+ const double seconds = QgsExpressionUtils::getDoubleValue ( values.at ( 5 ), parent );
1144
+
1145
+ const QDate date ( year, month, day );
1146
+ if ( !date.isValid () )
1147
+ {
1148
+ parent->setEvalErrorString ( QObject::tr ( " '%1-%2-%3' is not a valid date" ).arg ( year ).arg ( month ).arg ( day ) );
1149
+ return QVariant ();
1150
+ }
1151
+ const QTime time ( hours, minutes, std::floor ( seconds ), ( seconds - std::floor ( seconds ) ) * 1000 );
1152
+ if ( !time.isValid () )
1153
+ {
1154
+ parent->setEvalErrorString ( QObject::tr ( " '%1-%2-%3' is not a valid time" ).arg ( hours ).arg ( minutes ).arg ( seconds ) );
1155
+ return QVariant ();
1156
+ }
1157
+ return QVariant ( QDateTime ( date, time ) );
1158
+ }
1159
+
1106
1160
static QVariant fcnCoalesce ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * )
1107
1161
{
1108
1162
for ( const QVariant &value : values )
@@ -5738,6 +5792,21 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
5738
5792
<< new QgsStaticExpressionFunction ( QStringLiteral ( " epoch" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " date" ) ), fcnEpoch, QStringLiteral ( " Date and Time" ) )
5739
5793
<< new QgsStaticExpressionFunction ( QStringLiteral ( " datetime_from_epoch" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " long" ) ), fcnDateTimeFromEpoch, QStringLiteral ( " Date and Time" ) )
5740
5794
<< new QgsStaticExpressionFunction ( QStringLiteral ( " day_of_week" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " date" ) ), fcnDayOfWeek, QStringLiteral ( " Date and Time" ) )
5795
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " make_date" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " year" ) )
5796
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " month" ) )
5797
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " day" ) ),
5798
+ fcnMakeDate, QStringLiteral ( " Date and Time" ) )
5799
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " make_time" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " hour" ) )
5800
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " minute" ) )
5801
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " second" ) ),
5802
+ fcnMakeTime, QStringLiteral ( " Date and Time" ) )
5803
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " make_datetime" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " year" ) )
5804
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " month" ) )
5805
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " day" ) )
5806
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " hour" ) )
5807
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " minute" ) )
5808
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " second" ) ),
5809
+ fcnMakeDateTime, QStringLiteral ( " Date and Time" ) )
5741
5810
<< new QgsStaticExpressionFunction ( QStringLiteral ( " lower" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ), fcnLower, QStringLiteral ( " String" ) )
5742
5811
<< new QgsStaticExpressionFunction ( QStringLiteral ( " upper" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ), fcnUpper, QStringLiteral ( " String" ) )
5743
5812
<< new QgsStaticExpressionFunction ( QStringLiteral ( " title" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ), fcnTitle, QStringLiteral ( " String" ) )
0 commit comments