|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-11-11 13:55 UTC] maarten at react dot com
Description:
------------
DateTime->setTimezone() is very slow on dates in the far future (or history), and the time needed isnt monotonic for greater dates.
ie. setTimezone() on a DateTime(PHP_INT_MAX) /* 64 bit max */ takes 0.05 seconds, but takes 250 whole seconds for PHP_INT_MAX/2 .
Using the $timezone parameter of the DateTime constructor is always fast though.
Test script:
---------------
$start = microtime(1);
$date = new DateTime('@'.(PHP_INT_MAX));
// $date = new DateTime('@'.(int)(PHP_INT_MAX / 2));
$date->setTimezone(new DateTimeZone('Europe/Amsterdam'));
echo microtime(1) - $start;
Expected result:
----------------
A faster change of the timezone; performance equal to using the constructor parameter
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 17:00:01 2025 UTC |
Tested in 5.3.6, and appears to be fixed. $date = new DateTime('@'.(int)(PHP_INT_MAX / 2)); now takes less than 1ms. :)