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);
$ordinalDay = $date->ordinal('day');
// Convert strftime format to PHP date format
$phpFormat = ExpressionUtils::strftimeToPhpFormat($strftimeExp);
// Split the format string by the ordinal day placeholder
$parts = explode('<<ordinal_day>>', $phpFormat);
if (count($parts) === 2) {
$before = $date->format($parts[0]);
$after = $date->format($parts[1]);
return $before . $ordinalDay . $after;
return $before.$ordinalDay.$after;
}
// Fallback: if no placeholder found, just format normally
return $date->format($phpFormat);
}
}

View file

@ -84,6 +84,7 @@ class ExpressionUtils
if (self::evaluateCondition($condition['left'], $variable, $object)) {
return true;
}
return self::evaluateCondition($condition['right'], $variable, $object);
case 'comparison':
@ -179,7 +180,7 @@ class ExpressionUtils
'%-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

View file

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

View file

@ -36,7 +36,7 @@ class BatteryLow extends Notification
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()
->data([

View file

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