php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62130 DateTime constructor accepts invalid TZ abbreviations
Submitted: 2012-05-23 19:52 UTC Modified: 2015-08-27 16:47 UTC
From: kavi at postpro dot net Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2012-05-23 19:52 UTC] kavi at postpro dot net
Description:
------------
PHP will accept invalid DST-related time zone abbreviations, e.g. daylight 
savings time when daylight savings time cannot be in effect on the given date; 
subsequent operations on the returned object may produce invalid results.

This should produce an error.

Test script:
---------------
        $dt = new DateTime('1980-01-01 15:00:00 PDT');
        print_r($dt);
        $dt->modify('+1 hour');
        print_r($dt);


Expected result:
----------------
EXPECTED output should be an error.


Actual result:
--------------
DateTime Object
(
    [date] => 1980-01-01 15:00:00
    [timezone_type] => 2
    [timezone] => PDT
)
DateTime Object
(
    [date] => 1980-01-01 15:00:00
    [timezone_type] => 2
    [timezone] => PDT
)


Note that PDT is invalid for the given date, and the modify() call didn't work 
and also didn't throw an error.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-27 16:47 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-08-27 16:47 UTC] cmb@php.net
IMO it is not a bug to accept a timezone identifier for a timezone
that may be currently not in use anywhere, because it is
nonetheless a valid timezone identifier. If an invalid timezone
identifier is given, an exception would be thrown, see
<https://3v4l.org/bvLtc>

> […] the modify() call didn't work and also didn't throw an
> error.

This bug has been fixed as of PHP 5.3.9, see
<https://3v4l.org/m2O7M>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC