chore: format
Some checks are pending
tests / ci (push) Waiting to run

This commit is contained in:
Benjamin Nussbaum 2025-10-06 23:47:27 +02:00
parent 161200df44
commit 8aea83703c
5 changed files with 25 additions and 23 deletions

View file

@ -35,21 +35,21 @@ class Date extends FiltersProvider
{ {
$date = Carbon::parse($dateStr); $date = Carbon::parse($dateStr);
$ordinalDay = $date->ordinal('day'); $ordinalDay = $date->ordinal('day');
// Convert strftime format to PHP date format // Convert strftime format to PHP date format
$phpFormat = ExpressionUtils::strftimeToPhpFormat($strftimeExp); $phpFormat = ExpressionUtils::strftimeToPhpFormat($strftimeExp);
// Split the format string by the ordinal day placeholder // Split the format string by the ordinal day placeholder
$parts = explode('<<ordinal_day>>', $phpFormat); $parts = explode('<<ordinal_day>>', $phpFormat);
if (count($parts) === 2) { if (count($parts) === 2) {
$before = $date->format($parts[0]); $before = $date->format($parts[0]);
$after = $date->format($parts[1]); $after = $date->format($parts[1]);
return $before . $ordinalDay . $after;
return $before.$ordinalDay.$after;
} }
// Fallback: if no placeholder found, just format normally // Fallback: if no placeholder found, just format normally
return $date->format($phpFormat); return $date->format($phpFormat);
} }
} }

View file

@ -84,6 +84,7 @@ class ExpressionUtils
if (self::evaluateCondition($condition['left'], $variable, $object)) { if (self::evaluateCondition($condition['left'], $variable, $object)) {
return true; return true;
} }
return self::evaluateCondition($condition['right'], $variable, $object); return self::evaluateCondition($condition['right'], $variable, $object);
case 'comparison': case 'comparison':
@ -179,7 +180,7 @@ class ExpressionUtils
'%-S' => 's', // Second without leading zero (Ruby) -> second 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' => 'O', // Timezone offset (Ruby) -> timezone offset (PHP)
'%Z' => 'T', // Timezone name (Ruby) -> timezone name (PHP) '%Z' => 'T', // Timezone name (Ruby) -> timezone name (PHP)
// Standard strftime conversions // Standard strftime conversions
'%A' => 'l', // Full weekday name '%A' => 'l', // Full weekday name
'%a' => 'D', // Abbreviated weekday name '%a' => 'D', // Abbreviated weekday name

View file

@ -237,7 +237,7 @@ class Plugin extends Model
// Converts to: {% assign temp_filtered = collection | filter: "key", "value" %}{% for item in temp_filtered %} // Converts to: {% assign temp_filtered = collection | filter: "key", "value" %}{% for item in temp_filtered %}
$template = preg_replace_callback( $template = preg_replace_callback(
'/{%\s*for\s+(\w+)\s+in\s+([^|%}]+)\s*\|\s*([^%}]+)%}/', '/{%\s*for\s+(\w+)\s+in\s+([^|%}]+)\s*\|\s*([^%}]+)%}/',
function ($matches): string { function (array $matches): string {
$variableName = mb_trim($matches[1]); $variableName = mb_trim($matches[1]);
$collection = mb_trim($matches[2]); $collection = mb_trim($matches[2]);
$filter = mb_trim($matches[3]); $filter = mb_trim($matches[3]);
@ -259,10 +259,11 @@ class Plugin extends Model
// Handle date filter formats: date: "format" or date: 'format' // Handle date filter formats: date: "format" or date: 'format'
$template = preg_replace_callback( $template = preg_replace_callback(
'/date:\s*(["\'])([^"\']+)\1/', '/date:\s*(["\'])([^"\']+)\1/',
function ($matches): string { function (array $matches): string {
$quote = $matches[1]; $quote = $matches[1];
$format = $matches[2]; $format = $matches[2];
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format); $convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
return 'date: '.$quote.$convertedFormat.$quote; return 'date: '.$quote.$convertedFormat.$quote;
}, },
$template $template
@ -271,13 +272,14 @@ class Plugin extends Model
// Handle l_date filter formats: l_date: "format" or l_date: 'format' // Handle l_date filter formats: l_date: "format" or l_date: 'format'
$template = preg_replace_callback( $template = preg_replace_callback(
'/l_date:\s*(["\'])([^"\']+)\1/', '/l_date:\s*(["\'])([^"\']+)\1/',
function ($matches): string { function (array $matches): string {
$quote = $matches[1]; $quote = $matches[1];
$format = $matches[2]; $format = $matches[2];
$convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format); $convertedFormat = \App\Liquid\Utils\ExpressionUtils::strftimeToPhpFormat($format);
return 'l_date: '.$quote.$convertedFormat.$quote; return 'l_date: '.$quote.$convertedFormat.$quote;
}, },
$template (string) $template
); );
return $template; return $template;

View file

@ -36,7 +36,7 @@ class BatteryLow extends Notification
return (new MailMessage)->markdown('mail.battery-low', ['device' => $this->device]); return (new MailMessage)->markdown('mail.battery-low', ['device' => $this->device]);
} }
public function toWebhook(object $notifiable): \App\Notifications\Messages\WebhookMessage public function toWebhook(object $notifiable): WebhookMessage
{ {
return WebhookMessage::create() return WebhookMessage::create()
->data([ ->data([

View file

@ -51,45 +51,44 @@ test('ordinalize filter handles different ordinal suffixes', function (): void {
// 1st // 1st
expect($filter->ordinalize('2025-01-01', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-01', '<<ordinal_day>>'))
->toBe('1st'); ->toBe('1st');
// 2nd // 2nd
expect($filter->ordinalize('2025-01-02', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-02', '<<ordinal_day>>'))
->toBe('2nd'); ->toBe('2nd');
// 3rd // 3rd
expect($filter->ordinalize('2025-01-03', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-03', '<<ordinal_day>>'))
->toBe('3rd'); ->toBe('3rd');
// 4th // 4th
expect($filter->ordinalize('2025-01-04', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-04', '<<ordinal_day>>'))
->toBe('4th'); ->toBe('4th');
// 11th (special case) // 11th (special case)
expect($filter->ordinalize('2025-01-11', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-11', '<<ordinal_day>>'))
->toBe('11th'); ->toBe('11th');
// 12th (special case) // 12th (special case)
expect($filter->ordinalize('2025-01-12', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-12', '<<ordinal_day>>'))
->toBe('12th'); ->toBe('12th');
// 13th (special case) // 13th (special case)
expect($filter->ordinalize('2025-01-13', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-13', '<<ordinal_day>>'))
->toBe('13th'); ->toBe('13th');
// 21st // 21st
expect($filter->ordinalize('2025-01-21', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-21', '<<ordinal_day>>'))
->toBe('21st'); ->toBe('21st');
// 22nd // 22nd
expect($filter->ordinalize('2025-01-22', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-22', '<<ordinal_day>>'))
->toBe('22nd'); ->toBe('22nd');
// 23rd // 23rd
expect($filter->ordinalize('2025-01-23', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-23', '<<ordinal_day>>'))
->toBe('23rd'); ->toBe('23rd');
// 24th // 24th
expect($filter->ordinalize('2025-01-24', '<<ordinal_day>>')) expect($filter->ordinalize('2025-01-24', '<<ordinal_day>>'))
->toBe('24th'); ->toBe('24th');
}); });