Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 49910)
+++ src/wp-includes/post.php	(working copy)
@@ -3685,6 +3685,8 @@
 		'guid'                  => '',
 		'import_id'             => 0,
 		'context'               => '',
+		'post_date'             => '',
+		'post_date_gmt'         => '',
 	);
 
 	$postarr = wp_parse_args( $postarr, $defaults );
@@ -3818,25 +3820,11 @@
 	}
 
 	/*
-	 * If the post date is empty (due to having been new or a draft) and status
-	 * is not 'draft' or 'pending', set date to now.
+	 * Resolve the post date from any provided post date or post date GMT strings;
+	 * if none are provided, the date will be set to now.
 	 */
-	if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' === $postarr['post_date'] ) {
-		if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
-			$post_date = current_time( 'mysql' );
-		} else {
-			$post_date = get_date_from_gmt( $postarr['post_date_gmt'] );
-		}
-	} else {
-		$post_date = $postarr['post_date'];
-	}
-
-	// Validate the date.
-	$mm         = substr( $post_date, 5, 2 );
-	$jj         = substr( $post_date, 8, 2 );
-	$aa         = substr( $post_date, 0, 4 );
-	$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
-	if ( ! $valid_date ) {
+	$post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] );
+	if ( ! $post_date ) {
 		if ( $wp_error ) {
 			return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
 		} else {
@@ -4522,6 +4510,39 @@
 }
 
 /**
+ * Uses wp_checkdate to return a valid Gregorian-calendar value for post_date.
+ * If post_date is not provided, this first checks post_date_gmt if provided,
+ * then falls back to use the current time.
+ *
+ * For back-compat purposes in wp_insert_post, an empty post_date and an invalid
+ * post_date_gmt will continue to return '1970-01-01 00:00:00' rather than false.
+ *
+ * @param string $post_date     The date in mysql format.
+ * @param string $post_date_gmt The GMT date in mysql format.
+ * @return string|false A valid Gregorian-calendar date string, or false on failure.
+ */
+function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) {
+	// If the date is empty, set the date to now. 
+	if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) {
+		if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) {
+			$post_date = current_time( 'mysql' );
+		} else {
+			$post_date = get_date_from_gmt( $post_date_gmt );
+		}
+	}
+
+	// Validate the date.
+	$mm         = substr( $post_date, 5, 2 );
+	$jj         = substr( $post_date, 8, 2 );
+	$aa         = substr( $post_date, 0, 4 );
+	$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
+	if ( ! $valid_date ) {
+		return false;
+	}
+	return $post_date;
+}
+
+/**
  * Computes a unique slug for the post, when given the desired slug and some post details.
  *
  * @since 2.8.0
Index: tests/phpunit/tests/post.php
===================================================================
--- tests/phpunit/tests/post.php	(revision 49910)
+++ tests/phpunit/tests/post.php	(working copy)
@@ -1395,4 +1395,210 @@
 		$tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
 		$this->assertSameSets( array( $tag_2['term_id'], $tag_3['term_id'] ), $tags );
 	}
+
+	/**
+	 * @ticket 52187
+	 */
+	public function test_insert_empty_post_date() {
+		$post_date_gmt = '2020-12-29 10:11:45';
+		$invalid_date  = '2020-12-41 14:15:27';
+
+		// Empty post_date_gmt with floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_status' => 'draft',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'draft',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+		// Empty post_date_gmt without floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_status' => 'publish',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'publish',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
+		$this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' );
+
+		// Valid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date_gmt' => $post_date_gmt,
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( get_date_from_gmt( $post_date_gmt ), $post->post_date );
+		$this->assertEquals( $post_date_gmt, $post->post_date_gmt );
+
+		// Invalid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date_gmt' => $invalid_date,
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( '1970-01-01 00:00:00', $post->post_date );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+	}
+
+	/**
+	 * @ticket 52187
+	 */
+	public function test_insert_valid_post_date() {
+		$post_date     = '2020-12-28 11:26:35';
+		$post_date_gmt = '2020-12-29 10:11:45';
+		$invalid_date  = '2020-12-41 14:15:27';
+
+		// Empty post_date_gmt with floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'   => $post_date,
+				'post_status' => 'draft',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $post_date,
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'draft',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+		// Empty post_date_gmt without floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'   => $post_date,
+				'post_status' => 'publish',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $post_date,
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'publish',
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
+
+		// Valid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $post_date,
+				'post_date_gmt' => $post_date_gmt,
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( $post_date_gmt, $post->post_date_gmt );
+
+		// Invalid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $post_date,
+				'post_date_gmt' => $invalid_date,
+			)
+		);
+		$post = get_post( $post_id );
+		$this->assertEquals( $post_date, $post->post_date );
+		$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+	}
+
+	/**
+	 * @ticket 52187
+	 */
+	public function test_insert_invalid_post_date() {
+		$post_date     = '2020-12-28 11:26:35';
+		$post_date_gmt = '2020-12-29 10:11:45';
+		$invalid_date  = '2020-12-41 14:15:27';
+
+		// Empty post_date_gmt with floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'   => $invalid_date,
+				'post_status' => 'draft',
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $invalid_date,
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'draft',
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+
+		// Empty post_date_gmt without floating status
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'   => $invalid_date,
+				'post_status' => 'publish',
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $invalid_date,
+				'post_date_gmt' => '0000-00-00 00:00:00',
+				'post_status'   => 'publish',
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+
+		// Valid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $invalid_date,
+				'post_date_gmt' => $post_date_gmt,
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+
+		// Invalid post_date_gmt
+		$post_id = self::factory()->post->create(
+			array(
+				'post_date'     => $invalid_date,
+				'post_date_gmt' => $invalid_date,
+			)
+		);
+		$this->assertEquals( 0, $post_id );
+	}
 }
