@@ -99,6 +99,8 @@ public static function evaluate(
9999 return self ::sqlCeiling ($ conn , $ scope , $ expr , $ row , $ result );
100100 case 'FLOOR ' :
101101 return self ::sqlFloor ($ conn , $ scope , $ expr , $ row , $ result );
102+ case 'CONVERT_TZ ' :
103+ return self ::sqlConvertTz ($ conn , $ scope , $ expr , $ row , $ result );
102104 case 'TIMESTAMPDIFF ' :
103105 return self ::sqlTimestampdiff ($ conn , $ scope , $ expr , $ row , $ result );
104106 case 'DATEDIFF ' :
@@ -1550,6 +1552,49 @@ private static function getPhpIntervalFromExpression(
15501552 }
15511553 }
15521554
1555+ /**
1556+ * @param FakePdoInterface $conn
1557+ * @param Scope $scope
1558+ * @param FunctionExpression $expr
1559+ * @param array<string, mixed> $row
1560+ * @param QueryResult $result
1561+ *
1562+ * @return string|null
1563+ * @throws ProcessorException
1564+ */
1565+ private static function sqlConvertTz (
1566+ FakePdoInterface $ conn ,
1567+ Scope $ scope ,
1568+ FunctionExpression $ expr ,
1569+ array $ row ,
1570+ QueryResult $ result )
1571+ {
1572+ $ args = $ expr ->args ;
1573+
1574+ if (count ($ args ) !== 3 ) {
1575+ throw new \InvalidArgumentException ("CONVERT_TZ() requires exactly 3 arguments " );
1576+ }
1577+
1578+ /** @var string|null $dtValue */
1579+ $ dtValue = Evaluator::evaluate ($ conn , $ scope , $ args [0 ], $ row , $ result );
1580+ /** @var string|null $fromTzValue */
1581+ $ fromTzValue = Evaluator::evaluate ($ conn , $ scope , $ args [1 ], $ row , $ result );
1582+ /** @var string|null $toTzValue */
1583+ $ toTzValue = Evaluator::evaluate ($ conn , $ scope , $ args [2 ], $ row , $ result );
1584+
1585+ if ($ dtValue === null || $ fromTzValue === null || $ toTzValue === null ) {
1586+ return null ;
1587+ }
1588+
1589+ try {
1590+ $ dt = new \DateTime ($ dtValue , new \DateTimeZone ($ fromTzValue ));
1591+ $ dt ->setTimezone (new \DateTimeZone ($ toTzValue ));
1592+ return $ dt ->format ('Y-m-d H:i:s ' );
1593+ } catch (\Exception $ e ) {
1594+ return null ;
1595+ }
1596+ }
1597+
15531598 /**
15541599 * @param FakePdoInterface $conn
15551600 * @param Scope $scope
0 commit comments