Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Processor/Expression/FunctionEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public static function evaluate(
return self::sqlBinary($conn, $scope, $expr, $row, $result);
case 'FROM_UNIXTIME':
return self::sqlFromUnixtime($conn, $scope, $expr, $row, $result);
case 'UNIX_TIMESTAMP':
return self::sqlUnixTimestamp($conn, $scope, $expr, $row, $result);
case 'GREATEST':
return self::sqlGreatest($conn, $scope, $expr, $row, $result);
case 'VALUES':
Expand Down Expand Up @@ -845,6 +847,32 @@ private static function sqlFromUnixtime(
return \date('Y-m-d H:i:s', (int) $column);
}

/**
* @param array<string, mixed> $row
*/
private static function sqlUnixTimestamp(
FakePdoInterface $conn,
Scope $scope,
FunctionExpression $expr,
array $row,
QueryResult $result
) : ?int {
$args = $expr->args;

switch (\count($args)) {
case 0:
return time();
case 1:
$column = Evaluator::evaluate($conn, $scope, $args[0], $row, $result);
if (!\is_string($column)) {
return null;
}
return \strtotime($column) ?: null;
default:
throw new ProcessorException("MySQL UNIX_TIMESTAPM() SQLFake only implemented for 0 or 1 argument");
}
}

/**
* @param array<string, mixed> $row
*
Expand Down