malzariey / filament-daterangepicker-filter

MIT License
105 stars 46 forks source link

useRangeLabels() doesn't seam to work #114

Closed buddhaCode closed 2 months ago

buddhaCode commented 2 months ago

I can't get this feature to work. I can simply see no difference in my GUI.

With useRangeLabels():

SCR-20240731-laxs

The field should contain "Letzten 7 Tage" and not "25.07.2024 - 31.07.2024", shouldn't it?

Without useRangeLabels():

SCR-20240731-lbqc

malzariey commented 2 months ago

Could you share your code?

buddhaCode commented 2 months ago

Sure. The code is pretty basic:

DateRangeFilter::make('valued_at')
  ->label('Wertstellung am')
  ->timezone(config('app.display_timezone'))
  ->displayFormat('DD.MM.YYYY')
  ->format('d.m.Y')
  ->withIndicator()
  ->useRangeLabels(),

Did I describe the intention of the feature correctly?

malzariey commented 2 months ago
DateRangeFilter::make('valued_at')
  ->label('Wertstellung am')
  ->timezone(config('app.display_timezone'))
  ->displayFormat('DD.MM.YYYY')
  ->format('d.m.Y')
  ->withIndicator()
  ->useRangeLabels(),

It works fine at my end, could you share a reproduction repo

image

buddhaCode commented 2 months ago

I found the cause of the issue. I am using Date::use(CarbonImmutable::class); in my AppServiceProvider. So all my dates are immutable. When I comment that out, it works perfectly fine. But I'm not sure why this is an issue, because this feature is totally JavaScript based.

    public static function table(Table $table): Table
    {
        Date::use(CarbonImmutable::class);

        return $table
            ->columns([
                TextColumn::make('test')
                    ->date(),
            ])
            ->filters([
                DateRangeFilter::make('test')
            ]);
    }
malzariey commented 2 months ago

Thanks for reporting

buddhaCode commented 2 months ago

Do you have any idea why using immutables influences this feature?

malzariey commented 2 months ago

The package is not using immutable Carbon and might have made a mismatch when comparing dates