Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime: build from timestamp use method setTimestamp() #300

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

h4kuna
Copy link
Contributor

@h4kuna h4kuna commented Sep 13, 2023

  • new feature? no, only update

  • BC break? no

  • doc PR: nette/docs#??? not need

  • keep right timezone

  • compact syntax

  • little bit faster, let's try

Test how I measure

function measure(callable $test): float
{
	$start = microtime(true);
	for ($i = 0; $i < 1000; ++$i) {
		$test($i);
	}
	return microtime(true) - $start;
}

echo 'Datetime' . PHP_EOL;
echo measure(static function (int $i) {
		return (new DateTime())->setTimestamp($i);
	}) . PHP_EOL;

echo measure(static function (int $i) {
		return (new DateTime('@' . $i))->setTimezone(new \DateTimeZone(date_default_timezone_get()));
	}) . PHP_EOL;

echo 'DatetimeImmutable' . PHP_EOL;
echo measure(static function (int $i) {
		return (new DateTimeImmutable())->setTimestamp($i);
	}) . PHP_EOL;

echo measure(static function (int $i) {
		return (new DateTimeImmutable('@' . $i))->setTimezone(new \DateTimeZone(date_default_timezone_get()));
	}) . PHP_EOL;

@dg dg force-pushed the master branch 3 times, most recently from f321e3f to c67c9f3 Compare September 19, 2023 10:11
@dg dg merged commit ace22e9 into nette:master Sep 19, 2023
13 checks passed
@dg
Copy link
Member

dg commented Sep 19, 2023

thanks

dg pushed a commit that referenced this pull request Sep 19, 2023
dg pushed a commit that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants