Automattic\WooCommerce\Admin\PluginsInstallLoggers

AsyncPluginsInstallLogger::get_timeframe()publicWC 1.0

Returns time frame for a given time in milliseconds.

Method of the class: AsyncPluginsInstallLogger{}

No Hooks.

Return

String. - Time frame.

Usage

$AsyncPluginsInstallLogger = new AsyncPluginsInstallLogger();
$AsyncPluginsInstallLogger->get_timeframe( $timeInMs );
$timeInMs(int) (required)
- time in milliseconds

AsyncPluginsInstallLogger::get_timeframe() code WC 9.0.1

function get_timeframe( $timeInMs ) {
	$time_frames = [
		[
			'name' => '0-2s',
			'max'  => 2,
		],
		[
			'name' => '2-5s',
			'max'  => 5,
		],
		[
			'name' => '5-10s',
			'max'  => 10,
		],
		[
			'name' => '10-15s',
			'max'  => 15,
		],
		[
			'name' => '15-20s',
			'max'  => 20,
		],
		[
			'name' => '20-30s',
			'max'  => 30,
		],
		[
			'name' => '30-60s',
			'max'  => 60,
		],
		[ 'name' => '>60s' ],
	];

	foreach ( $time_frames as $time_frame ) {
		if ( ! isset( $time_frame['max'] ) ) {
			return $time_frame['name'];
		}
		if ( $timeInMs < $time_frame['max'] * 1000 ) {
			return $time_frame['name'];
		}
	}
}