WordPress.org

Making WordPress.org

Changeset 10252


Ignore:
Timestamp:
09/11/2020 06:08:05 PM (7 weeks ago)
Author:
iandunn
Message:

Events: Convert session start time to WP timestamp for consistency.

Previously we were comparing a WP timestamp to a Unix timestamp, which sometimes resulted in the Unix timestamp being stored in the date_utc column. Depsite its name, that column actually stores _WP timestamps_, not Unix timestamps. With this commit, the column will now consistently have WP timestamps.

File:
1 edited

Legend:

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

    r10251 r10252  
    343343                            }
    344344
    345                             $event['start_timestamp'] = $this->get_wordcamp_start_time( $value, absint( $wordcamp->session_start_time ) );
     345                            $event['start_timestamp'] = $this->get_wordcamp_start_time(
     346                                $value,
     347                                absint( $wordcamp->session_start_time ),
     348                                $event['utc_offset']
     349                            );
     350
    346351                            break;
    347352
     
    430435     * Determine the best start time for a WordCamp.
    431436     *
    432      * The timestamp from the WordCamp post type only tell us the date that the camp is on, not when it starts.
    433      * The earliest session can be used to get the time that the camp starts, but it's likely to be inaccurate
     437     * The WP timestamp from the WordCamp post type only tell us the date that the camp is on, not what time it starts.
     438     * The earliest session Unix timestamp can be used to get the time that the camp starts, but it's likely to be inaccurate
    434439     * if it doesn't match the date from the WordCamp post. One common cause of that is when an event is
    435440     * postponed, but the organizers haven't gone through and updated all of the sessions yet.
    436441     *
    437      * @param string $start_date
    438      * @param string $first_session_start_time
    439      *
    440      * @return string
    441      */
    442     protected function get_wordcamp_start_time( $start_date, $first_session_start_time ) {
    443         $session_time_is_same_day = date( 'Ymd', $start_date ) === date( 'Ymd', $first_session_start_time );
    444 
    445         return $session_time_is_same_day ? $first_session_start_time : $start_date;
     442     * @param string $start_date               _WP_ timestamp.
     443     * @param string $first_session_start_time _Unix_ timestamp.
     444     * @param int    $utc_offset               The event's UTC offset in seconds.
     445     *
     446     * @return string Returns a _WP_ timestamp.
     447     */
     448    protected function get_wordcamp_start_time( $start_date, $first_session_start_time, $utc_offset ) {
     449        if ( ! $utc_offset ) {
     450            return $start_date;
     451        }
     452
     453        // Convert the Unix timestamp to a WP timestamp, so we can compare apples to apples.
     454        $first_session_wp         = (int) $first_session_start_time + $utc_offset;
     455        $session_time_is_same_day = date( 'Ymd', $start_date ) === date( 'Ymd', $first_session_wp );
     456
     457        return $session_time_is_same_day ? $first_session_wp : $start_date;
    446458    }
    447459
Note: See TracChangeset for help on using the changeset viewer.