diff --git a/src/flextype/core/Parsers/Expressions/DateExpression.php b/src/flextype/core/Parsers/Expressions/DateExpression.php index bb4be2f0..b33fbfe5 100644 --- a/src/flextype/core/Parsers/Expressions/DateExpression.php +++ b/src/flextype/core/Parsers/Expressions/DateExpression.php @@ -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)) + ]; } } diff --git a/tests/src/flextype/core/Parsers/Expressions/DateExpressionTest.php b/tests/src/flextype/core/Parsers/Expressions/DateExpressionTest.php index ea154e4d..881df6f8 100644 --- a/tests/src/flextype/core/Parsers/Expressions/DateExpressionTest.php +++ b/tests/src/flextype/core/Parsers/Expressions/DateExpressionTest.php @@ -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); }); \ No newline at end of file