Time Zone and hour format problem
-
Hi,
I have a time zone problem. I am in UTC-4 time zone and days change every day at 8:00 pm, not at 12:00 am. In settings page, hours are in UTC time.
Moreover, when I set hour format to
G\hi, after saving settings, G\\hi is set. Each time I save settings, “\” is added.Thank you
-
Hi @ads97129,
I tested the calendar and events list display with the dates and timezone, and I couldn’t replicate this on my end. To assist with further troubleshooting, would you please confirm how you have the timezone settings on your end, under Sugar Calendar » Settings, under the Time Zone section?
Regarding the hour format, I confirmed the issue with the format
G\hi, and I’ve shared this with the dev team. I’ll be in touch with an update on this.Kind regards.
Hi @paddyam ,
I confirm Time Zone is on Guadeloupe (UTC – 4) but days change like Time Zone is on UTC.
Regards.
My site is experiencing this issue as well. An upcoming event for later today is not shown via the Events List block. But events farther in the future are shown.
On Sugar Calendar, my “Time Zones” is set to “Off”. My “Default Time Zone” is set to “Los Angeles”.
For my site’s General Settings, my “Timezone” is set to “Los Angeles”
This is a major bug. Hopefully the devs can identify the issue. Thank you very much.
Our development team has confirmed an issue with the event date and time queries when displaying events on the Event List block. They’re working on a fix, which will be included in the next release.
In the meantime, you can use the custom snippet below to fix this issue.
function sc_lite_fix_missing_events_in_upcoming_events_block( $upcoming_events, $args, $atts ) {
if (
! function_exists( 'sugar_calendar' ) ||
sugar_calendar()->is_pro()
) {
return $upcoming_events;
}
global $wpdb;
$calendars_left_join = '';
$where_calendars = '';
// Get the category left join and where queries if necessary.
if ( ! empty( $args['calendar_ids'] ) ) {
$term_taxonomy_ids = array_filter( array_map( 'absint', $args['calendar_ids'] ) );
if ( ! empty( $term_taxonomy_ids ) ) {
$calendars_left_join = 'LEFT JOIN ' . $wpdb->term_relationships . ' ON ' . $wpdb->prefix . 'sc_events.object_id = ' . $wpdb->term_relationships . '.object_id';
$where_calendars = $wpdb->prepare(
'AND ( ' . $wpdb->term_relationships . '.term_taxonomy_id IN (%1$s) )',
implode( ',', $term_taxonomy_ids )
);
}
}
$select_query = 'SELECT ' . $wpdb->prefix . 'sc_events.id FROM ' . $wpdb->prefix . 'sc_events';
if ( ! empty( $calendars_left_join ) ) {
$select_query .= ' ' . $calendars_left_join;
}
$now = sugar_calendar_get_request_time( 'mysql' );
$today = gmdate( 'Y-m-d 00:00:00', strtotime( $now ) );
$where_query = $wpdb->prepare(
'WHERE ' . $wpdb->prefix . 'sc_events.status = "publish" AND ' . $wpdb->prefix . 'sc_events.object_subtype = "sc_event" AND ' . $wpdb->prefix . 'sc_events.start>= %s AND ' . $wpdb->prefix . 'sc_events.end>= %s',
$today,
$now
);
if ( ! empty( $where_calendars ) ) {
$where_query .= ' ' . $where_calendars;
}
if ( ! empty( $args['search'] ) ) {
$where_query .= $wpdb->prepare(
' AND ' . $wpdb->prefix . 'sc_events.title LIKE %s',
'%' . $wpdb->esc_like( $args['search'] ) . '%'
);
}
$order_by = $wpdb->prepare(
'ORDER BY ' . $wpdb->prefix . 'sc_events.start ASC LIMIT %d OFFSET %d',
$args['number'],
$args['offset']
);
$final_query = $select_query . ' ' . $where_query . ' ' . $order_by;
// The query below is prepared/sanitized individually.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$event_ids = $wpdb->get_results( $final_query );
if ( empty( $event_ids ) ) {
return [];
}
$sugar_calendar_events_args = [
'id__in' => wp_list_pluck( $event_ids, 'id' ),
'orderby' => 'start',
'order' => 'ASC',
];
return sugar_calendar_get_events( $sugar_calendar_events_args );
}
add_filter( 'sugar_calendar_helpers_get_upcoming_events_list_with_recurring', 'sc_lite_fix_missing_events_in_upcoming_events_block', 100, 3 );Could you please try it out and let us know how it goes?
Kind regards.
The snippet works on my site. Thank you!
Hi @bradley,
Thanks for letting us know, I’m happy to hear that this is working on your end.
Once we have the update available, you can safely disable the snippet.
Cheers!
I’m still using the snippet, and just wanted to note that in the admin view of the events, as a list, the times are off by ~7 hours. But the times are correct for site visitors.
On a staging site, I updated from 3.6.1 > 3.7.0 and there is still an issue with the time zones.
For example, I have an event published from 5:00 PM – 9:00 PM. On the list of events in the admin, the event says from 10:00 AM – 2:00 PM.
The snippet provided above is not fixing the issue [An upcoming event for later today is not shown via the Events List block] on the new version 3.7.0.
Hello @bradley and @ads97129,
Michael here, lead developer of Sugar Calendar. Thank you for reporting the issue. We apologize if we weren’t able to resolve this quickly as it was tricky to replicate the issue.
We believe we were able to replicate the issue. At least in our side, the problem occurs when the Sugar Calendar Settings -> Time Zones is set to “Off” and the Default Time Zone is set to another value other than “Floating” (see screenshot).
To resolve this issue, you can do either of the following:
1. Set the Default Time Zone to “Floating” (see screenshot).
2. Use this snippet:add_action( 'sugar_calendar_is_timezone_floating', 'sugar_calendar_fix_admin_timezone' );
/**
* Fix the issue where the timezone is considered even when it's disabled.
*
* @param bool $retval
*
* @return bool
*/
function sugar_calendar_fix_admin_timezone( $retval ) {
if (
class_exists( '\Sugar_Calendar\Options' ) &&
method_exists( '\Sugar_Calendar\Options', 'get' ) &&
\Sugar_Calendar\Options::get( 'timezone_type', 'off' ) === 'off'
) {
return true;
}
return $retval;
}If the issue persists, can you let us know what your settings are so we can help further? Thank you so much!
Hi @donmhico,
I’m using Version 3.7.2 and set the Default Time Zone to “Floating”
I also added the snippet. The times are correct on both the admin view and front calendar view, but the upcoming events block is still not showing (in admin or live) an event starting an hour from now.
Here’s the settings: https://jmp.sh/KLynDann
Note that I also tried setting to the Default Time Zone to “Los Angeles” but that didn’t work either.
Thank you for looking into this.
Hi @bradley and @ads97129,
Sean here!Thank you for the screenshot, but sorry, I’m still having difficulties in replicating the issue. I’ve tried to setup my site just like you mentioned (floating default timezone with either single or off timezone) and created an event an hour from the time I’m testing. Both mode of Event List block (normal or group by week turned off) shows my event on the frontend.
I’m worried that maybe I’m not troubleshooting the actual issue you’re having here. If possible, would you mind sharing me more screenshots for this issue? I’d like to see the Block settings you’re using for the Upcoming Events block.
Also, can you please check and let me know the WordPress timezone you’re in?
You can find this setting in: WordPress Admin > Settings > General
Another issue could be caused by your website cache. If you haven’t already, please try clearing it out and check if that’s the case.Hi Sean! @spiettojo ,
Block Settings: Events List
https://jmp.sh/HzDv9CPKMy WordPress “Timezone” is set to Los Angeles.
I also made sure to clear the site cache (Edge Cache and Object Cache).
I set the Sugar Calendar Default Time Zone to Floating. I tried using the snippet and turning it off.
I’m happy to provide more screenshots, just let me know. Thank you so much!
Thanks for your continued patience.
I received an update from the dev team, and while we had a challenge replicating the issue as described, we narrowed down the problem to the query and included a potential fix. To fix the issue, could you please replace the current snippet with this one and let me know if it works?
// Fixes Upcoming Events Block timezone issues.
add_filter( 'sugar_calendar_helpers_get_upcoming_events_list_with_recurring', 'sc_lite_fix_missing_events_in_upcoming_events_block', 10, 3 );
/**
* Implements the fix for issues with upcoming events timezone.
*
* @param Event[]|false $upcoming_events The upcoming events list with recurring events.
* @param array $args The arguments to get the events.
* @param array $attributes The block attributes.
*
* @return Event[]
*/
function sc_lite_fix_missing_events_in_upcoming_events_block( $upcoming_events, $args, $attributes ) {
if (
! function_exists( 'sugar_calendar' ) ||
sugar_calendar()->is_pro()
) {
return $upcoming_events;
}
global $wpdb;
$calendars_left_join = '';
$where_calendars = '';
// Get the category left join and where queries if necessary.
if ( ! empty( $args['calendar_ids'] ) ) {
if ( ! is_array( $args['calendar_ids'] ) ) {
$args['calendar_ids'] = [ $args['calendar_ids'] ];
}
$term_taxonomy_ids = array_filter( array_map( 'absint', $args['calendar_ids'] ) );
if ( ! empty( $term_taxonomy_ids ) ) {
$calendars_left_join = 'LEFT JOIN ' . $wpdb->term_relationships . ' AS cal_terms ON ' . $wpdb->prefix . 'sc_events.object_id = cal_terms.object_id';
$where_calendars = $wpdb->prepare(
'AND ( cal_terms.term_taxonomy_id IN (%1$s) )',
implode( ',', $term_taxonomy_ids )
);
}
}
$select_query = 'SELECT ' . $wpdb->prefix . 'sc_events.id FROM ' . $wpdb->prefix . 'sc_events';
if ( ! empty( $calendars_left_join ) ) {
$select_query .= ' ' . $calendars_left_join;
}
$tz = sugar_calendar_get_timezone_type() === 'off' ? 'UTC' : sugar_calendar_get_timezone();
$tz = $tz === null ? 'UTC' : $tz;
$now = sc_lit_fix_get_request_time( 'mysql', $tz );
$today = gmdate( 'Y-m-d 00:00:00', strtotime( $now ) );
$where_query = $wpdb->prepare(
'WHERE ' . $wpdb->prefix . 'sc_events.status = "publish" AND ' . $wpdb->prefix . 'sc_events.object_subtype = "sc_event" AND '
. $wpdb->prefix . 'sc_events.start>= %s AND ' . $wpdb->prefix . 'sc_events.end>= %s',
$today,
$now
);
if ( ! empty( $where_calendars ) ) {
$where_query .= ' ' . $where_calendars;
}
if ( ! empty( $args['search'] ) ) {
$where_query .= $wpdb->prepare(
' AND ' . $wpdb->prefix . 'sc_events.title LIKE %s',
'%' . $wpdb->esc_like( $args['search'] ) . '%'
);
}
// Add tags filter.
if ( ! empty( $attributes['tags'] ) ) {
$tag_ids = array_filter( array_map( 'absint', $attributes['tags'] ) );
if ( ! empty( $tag_ids ) ) {
// Change the SELECT query to include tag term taxonomy ID.
$select_query = 'SELECT ' . $wpdb->prefix . 'sc_events.id, tag_terms.term_taxonomy_id AS tag_term_taxonomy_id FROM ' . $wpdb->prefix . 'sc_events';
// Add tag JOIN - using standard WordPress term relationships table.
$tag_taxonomy_id = Sugar_Calendar\Features\Tags\Common\Helpers::get_tags_taxonomy_id();
// Create tag-specific join clause.
$tags_join = 'INNER JOIN ' . $wpdb->term_relationships . ' AS tag_terms ON ' . $wpdb->prefix . 'sc_events.object_id = tag_terms.object_id';
$tags_join .= ' INNER JOIN ' . $wpdb->term_taxonomy . ' AS tag_taxonomy ON tag_terms.term_taxonomy_id = tag_taxonomy.term_taxonomy_id';
// Combine joins - if calendar join exists, append to it, otherwise use tag join.
if ( ! empty( $calendars_left_join ) ) {
$combined_join = $calendars_left_join . ' ' . $tags_join;
} else {
$combined_join = $tags_join;
}
// Update SELECT query with combined JOIN clause.
$select_query .= ' ' . $combined_join;
// Add tag WHERE clause - filter by taxonomy and tag IDs.
$placeholders = implode( ',', array_fill( 0, count( $tag_ids ), '%d' ) );
$where_query .= $wpdb->prepare(
' AND tag_taxonomy.taxonomy = %s AND tag_taxonomy.term_id IN (' . $placeholders . ')',
array_merge( [ $tag_taxonomy_id ], $tag_ids )
);
}
}
$order_by = $wpdb->prepare(
'ORDER BY ' . $wpdb->prefix . 'sc_events.start ASC LIMIT %d OFFSET %d',
$args['number'],
$args['offset']
);
$final_query = $select_query . ' ' . $where_query . ' ' . $order_by;
// The query is prepared/sanitized individually.
$event_ids = $wpdb->get_results( $final_query );
if ( empty( $event_ids ) ) {
return [];
}
$sugar_calendar_events_args = [
'id__in' => wp_list_pluck( $event_ids, 'id' ),
'orderby' => 'start',
'order' => 'ASC',
];
return sugar_calendar_get_events( $sugar_calendar_events_args );
}
/**
* Implements the fix helper.
*
* @param string $type The type of time to return.
* @param string $timezone The timezone to use.
*
* @return int The time in the requested format.
*/
function sc_lit_fix_get_request_time( $type = 'timestamp', $timezone = 'UTC' ) {
global $timestart;
// Get timestart, avoid overriding the global.
$current_timestart = absint( empty( $timestart ) ? microtime( true ) : $timestart );
// Ensure that timezone is set.
$timezone = empty( $timezone ) ? 'UTC' : $timezone;
// Get the offset if not UTC.
$is_utc = $timezone === 'UTC';
if ( ! $is_utc ) {
$offset = (int) sugar_calendar_get_timezone_offset(
[
'time' => $current_timestart,
'timezone' => $timezone,
'format' => 'seconds',
]
);
}
// What type of.
switch ( $type ) {
// 'Y-m-d H:i:s'.
case 'mysql':
case 'Y-m-d H:i:s':
$retval = $is_utc
? gmdate( 'Y-m-d H:i:s' )
: gmdate( 'Y-m-d H:i:s', ( $current_timestart + $offset ) );
break;
// Unix timestamp.
case 'timestamp':
case '':
$retval = $is_utc
? $current_timestart
: $current_timestart + $offset;
break;
// Mixed string.
default:
$retval = $is_utc
? gmdate( $type )
: gmdate( $type, ( $current_timestart + $offset ) );
break;
}
if ( is_numeric( $retval ) ) {
$retval = intval( $retval );
}
return $retval;
}To clarify, with this snippet, the block will query events based on the timezone setting under your Sugar Calendar » Settings section.
Let me know how it goes.
Regards
Unfortunately, the newest snippet still does not work on my site. I have other upcoming events, including tomorrow. But it won’t show the one hour test event starting in 30 minutes.
Hi @bradley,
Thanks for getting back to me and for the update.
It’s possible that this might be specific to your setup, as we’re having difficulty replicating it on our end.
To assist in narrowing down your setup, could you please open a support ticket and share the events export from your site. You can export this from your WordPress dashboard, Sugar Calendar » Tools page, under the Export tab)?
Thanks, and I look forward to having this resolved.
The topic ‘Time Zone and hour format problem’ is closed to new replies.