WordPress.org

Making WordPress.org

Changeset 10270


Ignore:
Timestamp:
09/16/2020 06:16:57 PM (6 weeks ago)
Author:
iandunn
Message:

Events: Add start_unix_timestamp and end_unix_timestamp fields.

The date and end_date fields are WP timestamps which reflect the event's local timezone. True Unix timestamps are needed for the Events Widget to display events in the user's local timezone.

Fixes #4480
See #core51130
Props Rarst, dd32, iandunn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10250 r10270  
    3535    define( 'THROTTLE_IP2LOCATION',      0 );
    3636
    37     defined( 'DAY_IN_SECONDS'  ) or define( 'DAY_IN_SECONDS', 60 * 60 * 24 );
     37    defined( 'HOUR_IN_SECONDS' ) or define( 'HOUR_IN_SECONDS', 60 * 60 );
     38    defined( 'DAY_IN_SECONDS'  ) or define( 'DAY_IN_SECONDS', HOUR_IN_SECONDS * 24 );
    3839    defined( 'WEEK_IN_SECONDS' ) or define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
    3940
     
    869870            'meetup'     => $event->meetup,
    870871            'meetup_url' => $event->meetup_url,
    871             'date'       => $event->date_utc, // TODO: DB stores a local date, not UTC.
     872
     873            /*
     874             * The `date_utc` column in the database is misnomed, and contains times in the event's local
     875             * timezone. So the `date` field in the response is the local time, and the `date_utc` field in
     876             * the response here is _actually_ UTC.
     877             */
     878            'date'       => $event->date_utc,
    872879            'end_date'   => $event->end_date,
     880            'start_unix_timestamp'  => strtotime( $event->date_utc ) - $event->date_utc_offset,
     881            'end_unix_timestamp'    => strtotime( $event->end_date ) - $event->date_utc_offset,
     882
    873883
    874884            'location'   => array(
     
    10321042                'date'       => '2020-02-21 00:00:00',
    10331043                'end_date'   => '2020-02-23 00:00:00',
     1044                'start_unix_timestamp' => strtotime( '2020-02-21 00:00:00' ) - 7 * HOUR_IN_SECONDS,
     1045                'end_unix_timestamp'   => strtotime( '2020-02-23 00:00:00' ) - 7 * HOUR_IN_SECONDS,
    10341046
    10351047                'location' => array(
     
    10571069                'date'       => '2020-06-04 00:00:00',
    10581070                'end_date'   => '2020-06-06 00:00:00',
     1071                'start_unix_timestamp' => strtotime( '2020-06-04 00:00:00' ) - 1 * HOUR_IN_SECONDS,
     1072                'end_unix_timestamp'   => strtotime( '2020-06-06 00:00:00' ) - 1 * HOUR_IN_SECONDS,
    10591073
    10601074                'location' => array(
     
    10831097                'date'       => '2020-10-27 00:00:00',
    10841098                'end_date'   => '2020-10-29 00:00:00',
     1099                'start_unix_timestamp' => strtotime( '2020-10-27 00:00:00' ) - 5 * HOUR_IN_SECONDS,
     1100                'end_unix_timestamp'   => strtotime( '2020-10-29 00:00:00' ) - 5 * HOUR_IN_SECONDS,
    10851101
    10861102                'location' => array(
     
    12711287            'meetup_url' => '',
    12721288            'date'       => '2018-05-27 12:00:00',
     1289
    12731290            'location'   => array(
    12741291                'location' => 'Everywhere',
     
    13411358        $raw_camp = $wpdb->get_row( "
    13421359            SELECT
    1343                 `title`, `url`, `meetup`, `meetup_url`, `date_utc`, `end_date`, `country`, `latitude`, `longitude`
     1360                `title`, `url`, `meetup`, `meetup_url`, `date_utc`, `date_utc_offset`, `end_date`, `country`, `latitude`, `longitude`
    13441361            FROM `wporg_events`
    13451362            WHERE
     
    13591376                'meetup'     => $raw_camp->meetup,
    13601377                'meetup_url' => $raw_camp->meetup_url,
     1378
     1379                // See notes about UTC in `get_events()`.
    13611380                'date'       => $raw_camp->date_utc,
    13621381                'end_date'   => $raw_camp->end_date,
     1382                'start_unix_timestamp'  => strtotime( $raw_camp->date_utc ) - $raw_camp->date_utc_offset,
     1383                'end_unix_timestamp'    => strtotime( $raw_camp->end_date ) - $raw_camp->date_utc_offset,
    13631384
    13641385                'location'   => array(
     
    14161437    if ( ! $found ) {
    14171438        $raw_discussion_group = $wpdb->get_row( "
    1418             SELECT `title`, `url`, `meetup`, `meetup_url`, `date_utc`, `end_date`, `country`, `latitude`, `longitude`
     1439            SELECT `title`, `url`, `meetup`, `meetup_url`, `date_utc`, `date_utc_offset`, `end_date`, `country`, `latitude`, `longitude`
    14191440            FROM `wporg_events`
    14201441            WHERE
     
    14351456                'meetup'     => $raw_discussion_group->meetup,
    14361457                'meetup_url' => $raw_discussion_group->meetup_url,
     1458
     1459                // See notes about UTC in `get_events()`.
    14371460                'date'       => $raw_discussion_group->date_utc,
    14381461                'end_date'   => $raw_discussion_group->end_date,
     1462                'start_unix_timestamp' => strtotime( $raw_discussion_group->date_utc ) - $raw_discussion_group->date_utc_offset,
     1463                'end_unix_timestamp'   => strtotime( $raw_discussion_group->end_date ) - $raw_discussion_group->date_utc_offset,
    14391464
    14401465                'location'   => array(
Note: See TracChangeset for help on using the changeset viewer.