@@ -94,6 +94,11 @@ public static function evaluate(
94
94
return self ::sqlDay ($ conn , $ scope , $ expr , $ row , $ result );
95
95
case 'LAST_DAY ' :
96
96
return self ::sqlLastDay ($ conn , $ scope , $ expr , $ row , $ result );
97
+ case 'CURDATE ' :
98
+ case 'CURRENT_DATE ' :
99
+ return self ::sqlCurDate ($ expr );
100
+ case 'WEEKDAY ' :
101
+ return self ::sqlWeekDay ($ conn , $ scope , $ expr , $ row , $ result );
97
102
}
98
103
99
104
throw new ProcessorException ("Function " . $ expr ->functionName . " not implemented yet " );
@@ -203,6 +208,10 @@ public static function getColumnSchema(
203
208
case 'NOW ' :
204
209
return new Column \DateTime ();
205
210
211
+ case 'CURDATE ' :
212
+ case 'CURRENT_DATE ' :
213
+ return new Column \Date ();
214
+
206
215
case 'DATE ' :
207
216
case 'LAST_DAY ' :
208
217
$ arg = Evaluator::getColumnSchema ($ expr ->args [0 ], $ scope , $ columns );
@@ -230,6 +239,7 @@ public static function getColumnSchema(
230
239
231
240
case 'DATEDIFF ' :
232
241
case 'DAY ' :
242
+ case 'WEEKDAY ' :
233
243
return new Column \IntColumn (false , 10 );
234
244
}
235
245
@@ -1007,6 +1017,49 @@ private static function sqlLastDay(
1007
1017
return (new \DateTimeImmutable ($ subject ))->format ('Y-m-t ' );
1008
1018
}
1009
1019
1020
+ /**
1021
+ * @param array<string, mixed> $row
1022
+ */
1023
+ private static function sqlCurDate (FunctionExpression $ expr ): string
1024
+ {
1025
+ $ args = $ expr ->args ;
1026
+
1027
+ if (\count ($ args ) !== 0 ) {
1028
+ throw new ProcessorException ("MySQL CURDATE() function takes no arguments. " );
1029
+ }
1030
+
1031
+ return (new \DateTimeImmutable ())->format ('Y-m-d ' );
1032
+ }
1033
+
1034
+ /**
1035
+ * @param array<string, mixed> $row
1036
+ */
1037
+ private static function sqlWeekDay (
1038
+ FakePdoInterface $ conn ,
1039
+ Scope $ scope ,
1040
+ FunctionExpression $ expr ,
1041
+ array $ row ,
1042
+ QueryResult $ result
1043
+ ) : ?int {
1044
+ $ args = $ expr ->args ;
1045
+
1046
+ if (\count ($ args ) !== 1 ) {
1047
+ throw new ProcessorException ("MySQL WEEKDAY() function must be called with one argument " );
1048
+ }
1049
+
1050
+ $ subject = Evaluator::evaluate ($ conn , $ scope , $ args [0 ], $ row , $ result );
1051
+
1052
+ if (!is_string ($ subject )) {
1053
+ throw new \TypeError ('Failed assertion ' );
1054
+ }
1055
+
1056
+ if (!$ subject || \strpos ($ subject , '0000-00-00 ' ) === 0 ) {
1057
+ return null ;
1058
+ }
1059
+
1060
+ return (int )(new \DateTimeImmutable ($ subject ))->format ('N ' );
1061
+ }
1062
+
1010
1063
/**
1011
1064
* @param array<string, mixed> $row
1012
1065
*
0 commit comments