Skip to content

Commit 8e57db5

Browse files
committed
feat(UNIX_TIMESTAMP): add basic support for UNIX_TIMESTAMP function
1 parent 4dc64f5 commit 8e57db5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Processor/Expression/FunctionEvaluator.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public static function evaluate(
7171
return self::sqlBinary($conn, $scope, $expr, $row, $result);
7272
case 'FROM_UNIXTIME':
7373
return self::sqlFromUnixtime($conn, $scope, $expr, $row, $result);
74+
case 'UNIX_TIMESTAMP':
75+
return self::sqlUnitTimestamp($conn, $scope, $expr, $row, $result);
7476
case 'GREATEST':
7577
return self::sqlGreatest($conn, $scope, $expr, $row, $result);
7678
case 'VALUES':
@@ -845,6 +847,30 @@ private static function sqlFromUnixtime(
845847
return \date('Y-m-d H:i:s', (int) $column);
846848
}
847849

850+
/**
851+
* @param array<string, mixed> $row
852+
*/
853+
private static function sqlUnixTimestamp(
854+
FakePdoInterface $conn,
855+
Scope $scope,
856+
FunctionExpression $expr,
857+
array $row,
858+
QueryResult $result
859+
) : int {
860+
$args = $expr->args;
861+
862+
if (\count($args) === 0) {
863+
return \time();
864+
}
865+
866+
if (\count($args) > 1) {
867+
throw new ProcessorException("MySQL UNIX_TIMESTAPM() SQLFake only implemented for 0 or 1 argument");
868+
}
869+
870+
$column = Evaluator::evaluate($conn, $scope, $args[0], $row, $result);
871+
return \strtotime($column);
872+
}
873+
848874
/**
849875
* @param array<string, mixed> $row
850876
*

0 commit comments

Comments
 (0)