@@ -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 ' :
@@ -1548,6 +1550,49 @@ private static function getPhpIntervalFromExpression(
15481550 }
15491551 }
15501552
1553+ /**
1554+ * @param FakePdoInterface $conn
1555+ * @param Scope $scope
1556+ * @param FunctionExpression $expr
1557+ * @param array<string, mixed> $row
1558+ * @param QueryResult $result
1559+ *
1560+ * @return string|null
1561+ * @throws ProcessorException
1562+ */
1563+ private static function sqlConvertTz (
1564+ FakePdoInterface $ conn ,
1565+ Scope $ scope ,
1566+ FunctionExpression $ expr ,
1567+ array $ row ,
1568+ QueryResult $ result )
1569+ {
1570+ $ args = $ expr ->args ;
1571+
1572+ if (count ($ args ) !== 3 ) {
1573+ throw new \InvalidArgumentException ("CONVERT_TZ() requires exactly 3 arguments " );
1574+ }
1575+
1576+ /** @var string|null $dtValue */
1577+ $ dtValue = Evaluator::evaluate ($ conn , $ scope , $ args [0 ], $ row , $ result );
1578+ /** @var string|null $fromTzValue */
1579+ $ fromTzValue = Evaluator::evaluate ($ conn , $ scope , $ args [1 ], $ row , $ result );
1580+ /** @var string|null $toTzValue */
1581+ $ toTzValue = Evaluator::evaluate ($ conn , $ scope , $ args [2 ], $ row , $ result );
1582+
1583+ if ($ dtValue === null || $ fromTzValue === null || $ toTzValue === null ) {
1584+ return null ;
1585+ }
1586+
1587+ try {
1588+ $ dt = new \DateTime ($ dtValue , new \DateTimeZone ($ fromTzValue ));
1589+ $ dt ->setTimezone (new \DateTimeZone ($ toTzValue ));
1590+ return $ dt ->format ('Y-m-d H:i:s ' );
1591+ } catch (\Exception $ e ) {
1592+ return null ;
1593+ }
1594+ }
1595+
15511596 /**
15521597 * @param FakePdoInterface $conn
15531598 * @param Scope $scope
0 commit comments