php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53294 DateTime->setTimezone() very slow far future dates
Submitted: 2010-11-11 13:55 UTC Modified: 2012-03-22 12:31 UTC
From: maarten at react dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.14 OS: 64 bit Centos
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: maarten at react dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-11 20:58 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2011-01-22 08:52 UTC] stas@php.net
-Status: Assigned +Status: Feedback
 [2011-01-22 08:52 UTC] stas@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2011-07-25 14:36 UTC] maarten at react dot com
Tested in 5.3.6, and appears to be fixed.

$date = new DateTime('@'.(int)(PHP_INT_MAX / 2));
now takes less than 1ms. :)
 [2012-03-21 16:48 UTC] php dot net at doppy dot nl
Seems to be fixed for me as well.


------------
PHP 5.3.10-1ubuntu2 with Suhosin-Patch (cli) (built: Mar  5 2012 18:27:21)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

on 64bit.
 [2012-03-22 12:31 UTC] maarten at react dot com
-Status: Feedback +Status: Closed
 [2012-03-22 12:31 UTC] maarten at react dot com
I confirmed it was already fixed in 5.3.6, and a 3rd person (php dot net at doppy dot nl) confirmed it for 5.3.10, so issue is resolved. :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 00:01:31 2025 UTC