Displaying Events/Calendar in a user-supplied time zone.

WordPress Event Management, Calendars & Registration Forums General Question Displaying Events/Calendar in a user-supplied time zone.

This topic contains 3 replies, has 2 voices, and was last updated by  Robert Marsden 8 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #20878

    Hi,

    We’re trying to display events and the calendar to each user in their own time zone. (we get the user’s time zone during registration and store it in user_meta)

    Can you suggest the easiest way to accomplish this, or point me to the correct codex entry that can enlighten me??

    Thanks, Rob

    • This topic was modified 8 years, 7 months ago by  Robert Marsden. Reason: typo
    • This topic was modified 8 years, 7 months ago by  Robert Marsden.
    • This topic was modified 8 years, 7 months ago by  Robert Marsden.
    • This topic was modified 8 years, 7 months ago by  Stephen Harris.
    Robert Marsden
    #20886

    Let me provide some clearer parameters.

    What we want to do:
    Logged-in user enters new events on front end using their timezone.
    Event calendars (both full and widget) display events in user’s time zone or UTC for non logged-in user.
    Individual event listings display events in user’s time zone or UTC for non logged-in user.

    Environment:
    WP install is set to UTC timezone.
    Users supply their time zone when registering.

    What we need:
    What scripts/functions would wee need to modify?
    eo_calendar shortcode mods seem clear enough.
    Required eo_fullcalendar mods are not very clear.
    Some direction on mods to FES would be helpful.

    Thanks again,
    Rob

    Robert Marsden
    #20894

    Hi Robert,

    The fullCalendar calendar is cached – so in order to have it render different times based on the user, you’ll want to disable that:

    add_filter( 'pre_transient_eo_full_calendar_public', '__return_null' );
    add_filter( 'pre_transient_eo_full_calendar_public_priv', '__return_null' );
    

    (actually you do no not need the first one, as that is only triggered when the user is not logged-in, in which case, you will not be making any modifications).

    As for the modifications you can use the hook eventorganiser_fullcalendar_event (see codex: http://codex.wp-event-organiser.com/hook-eventorganiser_fullcalendar_event.html). Warning: this filters each event (an array), allowing you to modify its properties, including ‘start’ and ‘end’. In 3.0.0 (due in just over a week), the JavaScript library used for the calendar was updated, and the data it expected differed.

    Specifically, there was a change in how all-day events were specified. In particular, pre-3.0.0:

    //$event refers to an event all-day on the 21st January
    echo $event['start']; //prints 2016-01-21T00:00
    echo $event['end']; //prints 2016-01-22T00:00
    

    in 3.0.0, this is now

    //notice the end date/time.
    echo $event['start']; //prints 2016-01-21T00:00
    echo $event['end']; //prints 2016-01-21T23:59
    

    Note, also that Event Organiser a stores end dates according the original standard. That is, its only in the context of the calendar shortcode that this data is adjusted.

    In that hook are you also given the event ID and occurrence ID, so you can get a DateTime object of the event’s start/end dates (see eo_get_the_start etc). And then change the timezone, and replace $event['start'] and $event['end'] with the date formatted as above, but in the user’s timezone.

    I shall have to get back to you regarding FES, but hopefully that’ll help you get started with the rendering of events in different timezones.

    Stephen Harris
    #20895

    I’d already started doing some close looking at fullcalendar and was in the right area, so this is exactly what I needed, and will make things go much more quickly.

    As to FES and dates/time, we’re looking to store all event datetimes in UTC, but allow the users to enter their date/times in their own timezone, so we’d be looking to grab and modify their submitted datetimes before storing them in the DB. To facilitate this, we’re running WP set to UTC. This alleviates the need to store each event’s submitted timezone and, I hope, will reduce DB lookups.

    Many thanks!

    • This reply was modified 8 years, 7 months ago by  Robert Marsden.
    • This reply was modified 8 years, 7 months ago by  Robert Marsden. Reason: Typos
    • This reply was modified 8 years, 7 months ago by  Robert Marsden.
    Robert Marsden
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.