Commit e1602fee53 for wordpress.org

commit e1602fee53f331df685bfb611d312e14bbcb3416
Author: westonruter <westonruter@git.wordpress.org>
Date:   Wed Oct 14 05:20:51 2026 +0000

    Code Quality: Remove redundant checks in `human_time_diff()`.

    Each branch of the `if`/`elseif` chain that chooses the unit of the time difference checked a lower bound that was already guaranteed by the previous branch not matching. These checks are removed, and the last branch becomes an `else`, which makes it explicit that `$since` is always set before it is passed to the `human_time_diff` filter. For the same reason, the `<= 1` clamps in the minute through year branches could never change the value, so they are removed too; only the seconds branch keeps its clamp, since a zero difference is still reported as "1 second". The result of `round()` is now cast to `int`, so that `_n()` receives the type it declares; the clamps had previously hidden this mismatch from PHPStan by making the type `float|int`.

    There is no change in behavior. New tests cover each unit threshold, both exactly at the threshold and one second below it, in both directions. This resolves the remaining errors in the `greaterOrEqual.alwaysTrue` PHPStan baseline, which is deleted.

    Developed in https://github.com/WordPress/wordpress-develop/pull/14005.
    Follow-up to r24582, r45573.

    Props soean, westonruter, sergeybiryukov.
    See #65817.

    Built from https://develop.svn.wordpress.org/trunk@64342


    git-svn-id: http://core.svn.wordpress.org/trunk@63492 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 552c5f17c2..f277c126ba 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -4012,46 +4012,28 @@ function human_time_diff( $from, $to = 0 ) {
 		}
 		/* translators: Time difference between two dates, in seconds. %s: Number of seconds. */
 		$since = sprintf( _n( '%s second', '%s seconds', $secs ), $secs );
-	} elseif ( $diff < HOUR_IN_SECONDS && $diff >= MINUTE_IN_SECONDS ) {
-		$mins = round( $diff / MINUTE_IN_SECONDS );
-		if ( $mins <= 1 ) {
-			$mins = 1;
-		}
+	} elseif ( $diff < HOUR_IN_SECONDS ) {
+		$mins = (int) round( $diff / MINUTE_IN_SECONDS );
 		/* translators: Time difference between two dates, in minutes. %s: Number of minutes. */
 		$since = sprintf( _n( '%s minute', '%s minutes', $mins ), $mins );
-	} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
-		$hours = round( $diff / HOUR_IN_SECONDS );
-		if ( $hours <= 1 ) {
-			$hours = 1;
-		}
+	} elseif ( $diff < DAY_IN_SECONDS ) {
+		$hours = (int) round( $diff / HOUR_IN_SECONDS );
 		/* translators: Time difference between two dates, in hours. %s: Number of hours. */
 		$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
-	} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
-		$days = round( $diff / DAY_IN_SECONDS );
-		if ( $days <= 1 ) {
-			$days = 1;
-		}
+	} elseif ( $diff < WEEK_IN_SECONDS ) {
+		$days = (int) round( $diff / DAY_IN_SECONDS );
 		/* translators: Time difference between two dates, in days. %s: Number of days. */
 		$since = sprintf( _n( '%s day', '%s days', $days ), $days );
-	} elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
-		$weeks = round( $diff / WEEK_IN_SECONDS );
-		if ( $weeks <= 1 ) {
-			$weeks = 1;
-		}
+	} elseif ( $diff < MONTH_IN_SECONDS ) {
+		$weeks = (int) round( $diff / WEEK_IN_SECONDS );
 		/* translators: Time difference between two dates, in weeks. %s: Number of weeks. */
 		$since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
-	} elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) {
-		$months = round( $diff / MONTH_IN_SECONDS );
-		if ( $months <= 1 ) {
-			$months = 1;
-		}
+	} elseif ( $diff < YEAR_IN_SECONDS ) {
+		$months = (int) round( $diff / MONTH_IN_SECONDS );
 		/* translators: Time difference between two dates, in months. %s: Number of months. */
 		$since = sprintf( _n( '%s month', '%s months', $months ), $months );
-	} elseif ( $diff >= YEAR_IN_SECONDS ) {
-		$years = round( $diff / YEAR_IN_SECONDS );
-		if ( $years <= 1 ) {
-			$years = 1;
-		}
+	} else {
+		$years = (int) round( $diff / YEAR_IN_SECONDS );
 		/* translators: Time difference between two dates, in years. %s: Number of years. */
 		$since = sprintf( _n( '%s year', '%s years', $years ), $years );
 	}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index c056229e9b..deab535195 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-64341';
+$wp_version = '7.2-alpha-64342';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.