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: -
From: gmblar+php at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.1.8 OS: MacOS 10.13
Private report: No CVE-ID:
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gmblar+php at gmail dot com
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC