filament-fullcalendar icon indicating copy to clipboard operation
filament-fullcalendar copied to clipboard

Timezone

Open invaders-xx opened this issue 1 year ago • 6 comments

My event's dates (start and end) are stored in database in UTC. But I want to display those dates using user's timezone.

So I have a resource's view showing events table : as you can see the dates in table are displayed using the right timezone. In the FullCalendar, we see that event are displayed using UTC event if i set :

public function getConfig(): array
    {
        return array_merge(parent::getConfig(), [
            'timeZone' => auth()->user()->timezone,
            'locale' => app()->getLocale(),
        ]);
    }
image

invaders-xx avatar Aug 01 '22 13:08 invaders-xx

do you have a column timezone in your users database?

saade avatar Aug 01 '22 14:08 saade

Of course ;-)

invaders-xx avatar Aug 01 '22 16:08 invaders-xx

I think you didn't implement momentTimezonePlugin : Timezone

invaders-xx avatar Aug 03 '22 15:08 invaders-xx

I think Timezone is already included on the global build?

saade avatar Aug 03 '22 17:08 saade

Maybe but I need to convert all dates (which care stored in UTC) in the user's timezone to display rightly.

invaders-xx avatar Aug 04 '22 13:08 invaders-xx

Hi @invaders-xx

Did you solve this?

My progress:

From full-calendar docs: https://fullcalendar.io/docs/timeZone the timezones are NOT converted unless a timezone plugin is used, except for the local timezone.

In my case, since my dates are all Carbon objects and reach the Fullcalendar script with the timezone part:

Array(1)
  0:
    description: "....."
    end: "2022-08-27T17:30:00.000000Z"
    id: 15
    orderStrict: true
    start: "2022-08-27T15:00:00.000000Z"
    title: "Test event"

if I use timeZone => 'local' in config/filament-fullcalendar.php

<?php

/**
 * Consider this file the root configuration object for FullCalendar.
 * Any configuration added here, will be added to the calendar.
 * @see https://fullcalendar.io/docs#toc
 */

return [
    'timeZone' => 'local',

    'locale' => config('app.locale'),
    ...

It converts the events time to the user's timezone automatically. Of course this doesn't use the $user->timezone property as you have it, but it displays the events in whatever timezone the user's browser/OS it set to.

(#48 was created to fix an exception when we explicitly set the timeZone to local 😓)

tiagof avatar Aug 28 '22 17:08 tiagof

@invaders-xx @tiagof please try this new release and see if the timezone issue still appears

saade avatar Sep 25 '22 03:09 saade