ActionScheduler_ListTable::human_interval()private staticWC 1.0

Convert an interval of seconds into a two part human friendly string.

The WordPress human_time_diff() function only calculates the time difference to one degree, meaning even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step further to display two degrees of accuracy.

Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/

Метод класса: ActionScheduler_ListTable{}

Хуков нет.

Возвращает

Строку. A human friendly string representation of the interval.

Использование

$result = ActionScheduler_ListTable::human_interval( $interval, $periods_to_include );
$interval(int) (обязательный)
A interval in seconds.
$periods_to_include(int)
Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included.
По умолчанию: 2

Код ActionScheduler_ListTable::human_interval() WC 8.7.0

private static function human_interval( $interval, $periods_to_include = 2 ) {

	if ( $interval <= 0 ) {
		return __( 'Now!', 'woocommerce' );
	}

	$output = '';

	for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) {

		$periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] );

		if ( $periods_in_interval > 0 ) {
			if ( ! empty( $output ) ) {
				$output .= ' ';
			}
			$output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
			$seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds'];
			$periods_included++;
		}
	}

	return $output;
}