mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
fix(#95): improve compatibilty with strftime in Liquid for date and l_date filters
This commit is contained in:
parent
c8f6dd3bec
commit
23a7a217db
1 changed files with 17 additions and 4 deletions
|
|
@ -256,13 +256,26 @@ class Plugin extends Model
|
||||||
*/
|
*/
|
||||||
private function convertDateFormats(string $template): string
|
private function convertDateFormats(string $template): string
|
||||||
{
|
{
|
||||||
// Handle date filter formats: date: "format"
|
// Handle date filter formats: date: "format" or date: 'format'
|
||||||
$template = preg_replace_callback(
|
$template = preg_replace_callback(
|
||||||
'/date:\s*"([^"]+)"/',
|
'/date:\s*(["\'])([^"\']+)\1/',
|
||||||
function ($matches): string {
|
function ($matches): string {
|
||||||
$format = $matches[1];
|
$quote = $matches[1];
|
||||||
|
$format = $matches[2];
|
||||||
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
|
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
|
||||||
return 'date: "'.$convertedFormat.'"';
|
return 'date: '.$quote.$convertedFormat.$quote;
|
||||||
|
},
|
||||||
|
$template
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle l_date filter formats: l_date: "format" or l_date: 'format'
|
||||||
|
$template = preg_replace_callback(
|
||||||
|
'/l_date:\s*(["\'])([^"\']+)\1/',
|
||||||
|
function ($matches): string {
|
||||||
|
$quote = $matches[1];
|
||||||
|
$format = $matches[2];
|
||||||
|
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
|
||||||
|
return 'l_date: '.$quote.$convertedFormat.$quote;
|
||||||
},
|
},
|
||||||
$template
|
$template
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue