php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75088 getTransitions is slow with large values
Submitted: 2017-08-17 20:10 UTC Modified: 2018-01-14 13:07 UTC
From: gmblar+php at gmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 7.1.8 OS: MacOS 10.13
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
45 + 24 = ?
Subscribe to this entry?

 
 [2017-08-17 20:10 UTC] gmblar+php at gmail dot com
Description:
------------
getTransitions is slow with large negative or positive values. With the default values PHP_INT_MIN and PHP_INT_MAX the function takes a very long time.

Test script:
---------------
<?php


function measure_duration(callable $callback) {
    $start = microtime(true);
    call_user_func($callback);
    $duration = microtime(true) - $start;
    printf("Duration: %s\n\n", number_format($duration, 6));
}

$timezone = new DateTimeZone('Europe/Berlin');

measure_duration(function() use($timezone) {
    printf("Default Value\n");
    $timezone->getTransitions();
});

measure_duration(function() use($timezone) {
    $timestamp = 0;
    printf("Timestamp for %s\n", date('Y-m-d H:i:s', $timestamp));
    $timezone->getTransitions($timestamp);
});

measure_duration(function() use($timezone) {
    $timestamp = -62135596800;
    printf("Timestamp for %s\n", date('Y-m-d H:i:s', $timestamp));
    $timezone->getTransitions($timestamp);
});


Expected result:
----------------
Default Value
Duration: 0.000268

Timestamp for 1970-01-01 00:00:00
Duration: 0.000134

Timestamp for 0001-01-01 00:00:00
Duration: 0.000161

Actual result:
--------------
Default Value
Duration: 0.018967

Timestamp for 1970-01-01 00:00:00
Duration: 0.000101

Timestamp for 0001-01-01 00:00:00
Duration: 0.000095

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-14 13:07 UTC] gmblar+php at gmail dot com
-Status: Open +Status: Closed
 [2018-01-14 13:07 UTC] gmblar+php at gmail dot com
Fixed in PHP 7.2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC