llazzaro / django-scheduler

A calendaring app for Django.
BSD 3-Clause "New" or "Revised" License
1.27k stars 391 forks source link

Timezone localization not correct when used with fullcalendar #556

Open lausek opened 10 months ago

lausek commented 10 months ago

When used together with fullcalendar the api endpoint uses the wrong query parameter to set the timezone. api_occurrences expects a query parameter called timezone, but fullcalendar sends it as timeZone (see Latest Docs). Consequently, the backend does not localize timestamps at all and falls back to UTC.

As fullcalendar is a popular addition to django-scheduler, I think the backend should be able to handle both query parameter names.

Possible fix

If timezone wasn't found in the query, try again with timeZone:

    if not timezone:
        timezone = request.GET.get("timeZone")

https://github.com/llazzaro/django-scheduler/blob/8aa6f877f17e5b05f17d7c39e93d8e73625b0a65/schedule/views.py#L340C1-L340C1

Possible workaround

When defining the fullcalendar instance in the frontend, the timezone can be added manually to the events endpoint:

// defaults to UTC
var calendar = new FullCalendar.Calendar(mountNode, {
    events: "/schedule/api/occurrences?calendar_slug=default",
    timeZone: "Europe/Berlin",
    // ...
});

// Uses the correct timezone in backend
var calendar = new FullCalendar.Calendar(mountNode, {
    events: "/schedule/api/occurrences?calendar_slug=default&timezone=Europe%2FBerlin",
    timeZone: "Europe/Berlin",
    // ...
});

Additional information