1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(expressions): add new time and strtotime expressions

This commit is contained in:
Awilum
2022-09-13 12:29:51 +03:00
parent e9e6111ccc
commit 2ce6bda782
2 changed files with 17 additions and 1 deletions

View File

@@ -25,6 +25,10 @@ class DateExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [new ExpressionFunction('date', static fn (string $format, ?int $timestamp = null): string => '\date($format, $timestamp)', static fn (array $arguments, string $format, ?int $timestamp = null): string => \date($format, $timestamp))];
return [
new ExpressionFunction('date', static fn (string $format, ?int $timestamp = null): string => '\date($format, $timestamp)', static fn (array $arguments, string $format, ?int $timestamp = null): string => \date($format, $timestamp)),
new ExpressionFunction('time', static fn (): string => '\time()', static fn (array $arguments): string => \time()),
new ExpressionFunction('strtotime', static fn (string $datetime, ?int $baseTimestamp = null): int|false => '\strtotime($datetime, $baseTimestamp)', static fn (array $arguments, string $datetime, ?int $baseTimestamp = null): int|false => \strtotime($datetime, $baseTimestamp))
];
}
}

View File

@@ -16,4 +16,16 @@ test('date expression', function () {
$date = date("F j, Y, g:i a");
entries()->create('date', ['test' => '[[ date("F j, Y, g:i a") ]]']);
expect(entries()->fetch('date')['test'])->toBe($date);
});
test('time expression', function () {
$time = time();
entries()->create('time', ['test' => '[[ time() ]]']);
expect(entries()->fetch('time')['test'])->toBe($time);
});
test('strtotime expression', function () {
$date = strtotime("10 September 2000");
entries()->create('strtotime', ['test' => '[[ strtotime("10 September 2000"); ]]']);
expect(entries()->fetch('strtotime')['test'])->toBe($date);
});