Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/abilities/class-wp-abilities-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ private function format_date( WP_Post $post, string $field, bool $gmt ): ?string
*/
$date = ( $gmt ? $datetime->setTimezone( new DateTimeZone( 'UTC' ) ) : $datetime )->format( 'c' );

return rest_parse_date( $date ) ? $date : null;
return false !== rest_parse_date( $date ) ? $date : null;
}

/**
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -5689,6 +5689,42 @@ public function test_malformed_date_is_null( string $field, string $column ): vo
$this->assertNull( $result['items'][0][ $object ][ $key ], 'A malformed date should be null.' );
}

/**
* A stored date at the Unix epoch is returned: a timestamp of zero is a date, not a
* date that could not be parsed.
*
* @ticket 66812
* @since 7.3.0
*
* @dataProvider data_date_fields
*
* @param string $field The field path to request, such as `date.site`.
* @param string $column The cached post column to set to the Unix epoch.
*/
public function test_date_at_the_unix_epoch_is_returned( string $field, string $column ): void {
$this->login_as( 'administrator' );
$this->register_ability();

$post_id = self::factory()->post->create( array( 'post_status' => 'publish' ) );

$this->replace_cached_post_date_columns( $post_id, array( $column => '1970-01-01 00:00:00' ) );

list( $object, $key ) = explode( '.', $field );

$result = wp_get_ability( 'core/content-query' )->execute(
array(
'where' => array(
'type' => 'post',
'ids' => array( $post_id ),
),
'fields' => array( 'id', $field ),
)
);

$this->assertIsArray( $result, 'A date at the Unix epoch should pass output validation.' );
$this->assertSame( '1970-01-01T00:00:00+00:00', $result['items'][0][ $object ][ $key ] ?? null, 'A date at the Unix epoch should be returned.' );
}

/**
* Returns `where.author` values that are not an object holding an ID or a slug: values
* that are not objects, empty values, and objects with an unknown property.
Expand Down
Loading