WordPress.org

Making WordPress.org

Changeset 10244


Ignore:
Timestamp:
09/10/2020 12:21:24 AM (7 weeks ago)
Author:
iandunn
Message:

Official Events: Store WordCamp UTC offset.

This is needed for the Events Widget to display events in the user's timezone. We're already storing it for meetups, and it was recently added to the WordCamp.org API as well.

See https://github.com/WordPress/wordcamp.org/issues/567
See #4480
See #core51330

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r9854 r10244  
    332332                foreach ( $wordcamp as $field => $value ) {
    333333                    switch ( $field ) {
     334                        // This is the local time, not a true Unix timestamp.
    334335                        case 'Start Date (YYYY-mm-dd)':
    335336                            $value = absint( $value );
     
    344345                            break;
    345346
     347                        // This is the local time, not a true Unix timestamp.
    346348                        case 'End Date (YYYY-mm-dd)':
    347349                            $event['end_timestamp'] = absint( $value );
     
    392394                if ( $event['start_timestamp'] && empty( $event['end_timestamp'] ) ) {
    393395                    $event['end_timestamp'] = $event['start_timestamp'];
     396                }
     397
     398                if ( $wordcamp->{'Event Timezone'} && $event['start_timestamp'] ) {
     399                    $wordcamp_timezone = new DateTimeZone( $wordcamp->{'Event Timezone'} );
     400
     401                    $wordcamp_datetime = new DateTime(
     402                        '@' . $event['start_timestamp'],
     403                        $wordcamp_timezone
     404                    );
     405
     406                    $event['utc_offset'] = $wordcamp_timezone->getOffset( $wordcamp_datetime );
    394407                }
    395408
     
    569582            }
    570583
     584            /*
     585             * Convert to local time, because the `date_utc` column in `wporg_events` is misnomed and actually
     586             * expects the _local_ time.
     587             */
    571588            $start_timestamp = ( $meetup['time'] / 1000 ) + ( $meetup['utc_offset'] / 1000 ); // convert to seconds
    572589            $latitude        = ! empty( $meetup['venue']['lat'] ) ? $meetup['venue']['lat'] : $meetup['group']['lat'];
Note: See TracChangeset for help on using the changeset viewer.