diff --git a/app/Liquid/Utils/ExpressionUtils.php b/app/Liquid/Utils/ExpressionUtils.php index 9715de2..924bcf0 100644 --- a/app/Liquid/Utils/ExpressionUtils.php +++ b/app/Liquid/Utils/ExpressionUtils.php @@ -168,6 +168,19 @@ class ExpressionUtils public static function strftimeToPhpFormat(string $strftimeFormat): string { $conversions = [ + // Special Ruby format cases + '%N' => 'u', // Microseconds (Ruby) -> microseconds (PHP) + '%u' => 'u', // Microseconds (Ruby) -> microseconds (PHP) + '%-m' => 'n', // Month without leading zero (Ruby) -> month without leading zero (PHP) + '%-d' => 'j', // Day without leading zero (Ruby) -> day without leading zero (PHP) + '%-H' => 'G', // Hour without leading zero (Ruby) -> hour without leading zero (PHP) + '%-I' => 'g', // Hour 12h without leading zero (Ruby) -> hour 12h without leading zero (PHP) + '%-M' => 'i', // Minute without leading zero (Ruby) -> minute without leading zero (PHP) + '%-S' => 's', // Second without leading zero (Ruby) -> second without leading zero (PHP) + '%z' => 'O', // Timezone offset (Ruby) -> timezone offset (PHP) + '%Z' => 'T', // Timezone name (Ruby) -> timezone name (PHP) + + // Standard strftime conversions '%A' => 'l', // Full weekday name '%a' => 'D', // Abbreviated weekday name '%B' => 'F', // Full month name diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 2fd3718..74cb5bf 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -216,14 +216,14 @@ class Plugin extends Model */ private function applyLiquidReplacements(string $template): string { - $replacements = [ - 'date: "%N"' => 'date: "u"', - 'date: "%u"' => 'date: "u"', - '%-m/%-d/%Y' => 'm/d/Y', - ]; + + $replacements = []; // Apply basic replacements $template = str_replace(array_keys($replacements), array_values($replacements), $template); + + // Convert Ruby/strftime date formats to PHP date formats + $template = $this->convertDateFormats($template); // Convert {% render "template" with %} syntax to {% render "template", %} syntax $template = preg_replace( @@ -251,6 +251,25 @@ class Plugin extends Model return $template; } + /** + * Convert Ruby/strftime date formats to PHP date formats in Liquid templates + */ + private function convertDateFormats(string $template): string + { + // Handle date filter formats: date: "format" + $template = preg_replace_callback( + '/date:\s*"([^"]+)"/', + function ($matches): string { + $format = $matches[1]; + $convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format); + return 'date: "'.$convertedFormat.'"'; + }, + $template + ); + + return $template; + } + /** * Resolve Liquid variables in a template string using the Liquid template engine *