Make WordPress Core


Ignore:
Timestamp:
08/23/2019 02:14:07 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Simplify the date comparing logic in WP_Community_Events::trim_events().

The Events API returns event date without timezone information, so trying to parse it into a timestamp and compare to a WP timestamp is pointless.

Props Rarst.
Fixes #47463.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-community-events.php

    r43356 r45886  
    403403    protected function trim_events( $response_body ) {
    404404        if ( isset( $response_body['events'] ) ) {
    405             $wordcamps         = array();
    406             $current_timestamp = current_time( 'timestamp' );
     405            $wordcamps = array();
     406            $today     = current_time( 'Y-m-d' );
    407407
    408408            foreach ( $response_body['events'] as $key => $event ) {
     
    416416                }
    417417
    418                 $event_timestamp = strtotime( $event['date'] );
    419 
    420                 if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) {
     418                // We don't get accurate time with timezone from API, so we only take the date part (Y-m-d).
     419                $event_date = substr( $event['date'], 0, 10 );
     420
     421                if ( $today > $event_date ) {
    421422                    unset( $response_body['events'][ $key ] );
    422423                }
Note: See TracChangeset for help on using the changeset viewer.