Formatting: Add support for seconds to `human_time_diff()`.
The web has gotten so much faster since `human_time_diff()` was created, we need to be able to measure time differences with much finer granularity. Now, we can. Props johnjamesjacoby, pento. Fixes #35655. Built from https://develop.svn.wordpress.org/trunk@45573 git-svn-id: http://core.svn.wordpress.org/trunk@45384 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
00704114e0
commit
dd38e9cc0b
|
@ -3608,6 +3608,7 @@ function sanitize_email( $email ) {
|
||||||
* "5 mins", "2 days".
|
* "5 mins", "2 days".
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
|
* @since 5.3.0 Added support for showing a difference in seconds.
|
||||||
*
|
*
|
||||||
* @param int $from Unix timestamp from which the difference begins.
|
* @param int $from Unix timestamp from which the difference begins.
|
||||||
* @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
|
* @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
|
||||||
|
@ -3620,7 +3621,14 @@ function human_time_diff( $from, $to = '' ) {
|
||||||
|
|
||||||
$diff = (int) abs( $to - $from );
|
$diff = (int) abs( $to - $from );
|
||||||
|
|
||||||
if ( $diff < HOUR_IN_SECONDS ) {
|
if ( $diff < MINUTE_IN_SECONDS ) {
|
||||||
|
$secs = $diff;
|
||||||
|
if ( $secs <= 1 ) {
|
||||||
|
$secs = 1;
|
||||||
|
}
|
||||||
|
/* 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 );
|
$mins = round( $diff / MINUTE_IN_SECONDS );
|
||||||
if ( $mins <= 1 ) {
|
if ( $mins <= 1 ) {
|
||||||
$mins = 1;
|
$mins = 1;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.3-alpha-45572';
|
$wp_version = '5.3-alpha-45573';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue