HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/internal-links/helper/stopwatch.php
<?php
namespace ILJ\Helper;

/**
 * Stopwatch helper
 *
 * Keeps track of time for logging purposes
 *
 * @package ILJ\Helper
 * @since 2.23.4
 */
class Stopwatch {

	/**
	 * Start time value
	 *
	 * @var float
	 */
	private $start;

	/**
	 * Setup the stopwatch initial values
	 *
	 * @param  mixed $start
	 * @return void
	 */
	public function __construct($start = null) {
		if (null == $start) {
			$this->start = microtime(true);
		} else {
			$this->start = $start;
		}
	}

	/**
	 * Get current timestamp
	 *
	 * @return DateTime
	 */
	public static function timestamp(): \DateTime {
		return new \DateTime('now', self::timezone());
	}

	/**
	 * Get current timezone
	 *
	 * @return DateTimeZone
	 */
	public static function timezone(): \DateTimeZone {
		$offset  = get_option('gmt_offset');
		$hours   = (int) $offset;
		$minutes = ($offset - floor($offset)) * 60;
		return new \DateTimeZone(sprintf('%+03d:%02d', $hours, $minutes));
	}

	/**
	 * Get the runtime of the stopwatch
	 *
	 * @return float
	 */
	public function duration(): float {
		return round((microtime(true) - $this->start), 2);
	}

	/**
	 * Get the actual start time
	 *
	 * @return float
	 */
	public function get_start_time(): float {
		return $this->start;
	}
}