Timezone failing to get abbreviation for offset

Home Forums Calendar Products Events Calendar PRO Timezone failing to get abbreviation for offset

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1104979
    Brett
    Participant

    I found that all events were displaying the UTC offset rather than the timezone abbreviation. I’m not sure if this is specific to us, or if it is common. After a bit of research, I found that there is a more reliable method to finding the abbreviation than simply passing it to the DateTimeZone class.

    These are the changes made to more reliably get the abbreviation:

    In Timezones.php, change the abbr function:

    
    public static function abbr( $date, $timezone_string ) {
            try {
                if (strpos($timezone_string, 'UTC') === 0) {
                    $offset = substr($timezone_string, 3);
                    // Calculate seconds from offset
                    list($hours, $minutes) = explode(':', $offset);
                    $seconds = $hours * 60 * 60 + $minutes * 60;
                    // Get timezone name from seconds
                    $tz = timezone_name_from_abbr('', $seconds, 1);
                    // Workaround for bug #44780
                    if ($tz === false) $tz = timezone_name_from_abbr('', $seconds, 0);
    
                    $tz_date = date_create($date, new DateTimeZone($tz));
                    $formatted = $tz_date->format('T');
                    return $formatted;
                }
    
                $tz_date = date_create($date, new DateTimeZone($timezone_string));
                $formatted = $tz_date->format('T');
                return $formatted;
            } catch (Exception $e) {
                return '';
            }
    	}
    
    #1105496
    Brian
    Member

    Hi,

    Thanks for using our plugins and for sharing your coding here.

    This looks interesting and something we would want to look into.

    Can you submit a Pull Request in the develop branch of Tribe Common Repo for it:

    https://github.com/moderntribe/tribe-common

    Also, if you could share your research on why this method is better that would be helpful for us too.

    Let me know and thanks for sharing.

    Cheers

    #1111520
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Timezone failing to get abbreviation for offset’ is closed to new replies.