Making WordPress.org

Changeset 10251


Ignore:
Timestamp:
09/11/2020 06:08:02 PM (4 years ago)
Author:
iandunn
Message:

Official Events: Modularize calculation of WordCamp UTC offset.

File:
1 edited

Legend:

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

    r10244 r10251  
    328328                    'title'       => $wordcamp->title->rendered,
    329329                    'description' => $wordcamp->content->rendered,
     330                    'utc_offset'  => self::get_wordcamp_offset( $wordcamp ),
    330331                );
    331332
     
    396397                }
    397398
    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 );
    407                 }
    408 
    409399                $events[] = new Official_WordPress_Event( $event );
    410400            }
     
    412402
    413403        return $events;
     404    }
     405
     406    /**
     407     * Get a WordCamp's UTC offset in seconds.
     408     *
     409     * @param object $wordcamp
     410     *
     411     * @return int
     412     * @throws Exception
     413     */
     414    static function get_wordcamp_offset( $wordcamp ) {
     415        if ( ! $wordcamp->{'Event Timezone'} || ! $wordcamp->{'Start Date (YYYY-mm-dd)'} ) {
     416            return 0;
     417        }
     418
     419        $wordcamp_timezone = new DateTimeZone( $wordcamp->{'Event Timezone'} );
     420
     421        $wordcamp_datetime = new DateTime(
     422            '@' . $wordcamp->{'Start Date (YYYY-mm-dd)'},
     423            $wordcamp_timezone
     424        );
     425
     426        return $wordcamp_timezone->getOffset( $wordcamp_datetime );
    414427    }
    415428
Note: See TracChangeset for help on using the changeset viewer.