<?php

namespace Core;

class Clock
{
	/**
	 * Get current timestamp with millisecond part
	 * 
	 * @return Timestamp text as YYYY-MM-DD hh:mm:ss.fff
	 */
	static function getCurrentStamp()
	{
		$m = explode(" ", microtime());
		return date("Y-m-d H:i:s", $m[1]) . substr($m[0], 1, 4);
	}
	
	/**
	 * Get time text with total hours, minutes, seconds and milliseconds if specified
	 * 
	 * @param float $time
	 * @return string Time text as hh:mm:ss.fff
	 */
	static function getTimeText($time)
	{
		$f = !is_float($time) || ($u = fmod($time, 1)) == 0 ? '' : sprintf('.%03d', $u * 1000); 
		$h = $time / 3600;
		$time %= 3600;
		$m = $time / 60;
		$time %= 60;
		$s = $time;
		$time %= 1;
		return sprintf('%02d:%02d:%02d%s', $h, $m, $s, $f);
	}
}
