mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: add Liquid filter ordinalize
This commit is contained in:
parent
91e222f7a6
commit
c1786dfb6d
3 changed files with 128 additions and 0 deletions
|
|
@ -30,3 +30,66 @@ test('days_ago filter with large number works correctly', function (): void {
|
|||
|
||||
expect($filter->days_ago(100))->toBe($hundredDaysAgo);
|
||||
});
|
||||
|
||||
test('ordinalize filter formats date with ordinal day', function (): void {
|
||||
$filter = new Date();
|
||||
|
||||
expect($filter->ordinalize('2025-10-02', '%A, %B <<ordinal_day>>, %Y'))
|
||||
->toBe('Thursday, October 2nd, 2025');
|
||||
});
|
||||
|
||||
test('ordinalize filter handles datetime string with timezone', function (): void {
|
||||
$filter = new Date();
|
||||
|
||||
expect($filter->ordinalize('2025-12-31 16:50:38 -0400', '%A, %b <<ordinal_day>>'))
|
||||
->toBe('Wednesday, Dec 31st');
|
||||
});
|
||||
|
||||
test('ordinalize filter handles different ordinal suffixes', function (): void {
|
||||
$filter = new Date();
|
||||
|
||||
// 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');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue