Skip to content

Commit

Permalink
Date/Time: Simplify the date comparing logic in `WP_Community_Events:…
Browse files Browse the repository at this point in the history
…: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.

git-svn-id: https://develop.svn.wordpress.org/trunk@45886 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Aug 23, 2019
1 parent ece257f commit b975a25
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/wp-admin/includes/class-wp-community-events.php
Expand Up @@ -402,8 +402,8 @@ protected function format_event_data_time( $response_body ) {
*/
protected function trim_events( $response_body ) {
if ( isset( $response_body['events'] ) ) {
$wordcamps = array();
$current_timestamp = current_time( 'timestamp' );
$wordcamps = array();
$today = current_time( 'Y-m-d' );

foreach ( $response_body['events'] as $key => $event ) {
/*
Expand All @@ -415,9 +415,10 @@ protected function trim_events( $response_body ) {
continue;
}

$event_timestamp = strtotime( $event['date'] );
// We don't get accurate time with timezone from API, so we only take the date part (Y-m-d).
$event_date = substr( $event['date'], 0, 10 );

if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) {
if ( $today > $event_date ) {
unset( $response_body['events'][ $key ] );
}
}
Expand Down

0 comments on commit b975a25

Please sign in to comment.