php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67129 DateTimeZone incorrect offset for MDT
Submitted: 2014-04-24 18:28 UTC Modified: 2021-01-08 10:59 UTC
From: rmeyenburg at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 5.5.11 OS: Win7x64 (32bit PHP)
Private report: No CVE-ID: None
 [2014-04-24 18:28 UTC] rmeyenburg at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetimezone.getoffset
---

MDT (Mountain Daylight Time) is defined as UTC-6, while the PHP DateTimeZone object reports the offset as UTC-7 (same as MST/Mountain Standard Time).

Two tests are performed to check that day of the year (in or out of daylight saving's time) isn't effecting the result - MDT is always UTC-6 regardless of time of year (since UTC doesn't move)

Tested on PHP 5.5.11, 5.4.26, 5.3.28
NOTE: 5.5 differs from 5.4, 5.3
Untested (although perhaps implied) other Daylight time zones (PDT,CDT,EDT,ADT,NDT)


Test script:
---------------
<?php
$zone=new \DateTimeZone("MDT");

$o1=$zone->getOffset(new \DateTime("2012-01-01",$zone))/3600;
$o2=$zone->getOffset(new \DateTime("2012-08-01",$zone))/3600;
echo "2012-01-01: ".($o1==-6?"Pass":"Fail ($o1)")."\n";
echo "2012-08-01: ".($o2==-6?"Pass":"Fail ($o2)")."\n";

Expected result:
----------------
2012-01-01: Pass
2012-08-01: Pass

Actual result:
--------------
// 5.5.11-Win32-VC11-x86
2012-01-01: Fail (-7)
2012-08-01: Fail (-7)

// 5.4.26-Win32-VC9-x86
2012-01-01: Fail (-7)
2012-08-01: Pass

// 5.3.28-Win32-VC9-x86
2012-01-01: Fail (-7)
2012-08-01: Pass

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-26 14:36 UTC] sly at diglin dot com
I have also a similar error with date which are after the year 2037.
I use a timezone 'Europe/Berlin'

PHP 5.5.7 (cli) (built: Jan 28 2014 02:32:47) 
Zend Server 6
OS: OS X 10.9.3

Test Script:
<?php
$zone = new \DateTimeZone("Europe/Berlin");

$o1=$zone->getOffset(new \DateTime("2079-06-06 23:59:00",$zone))/3600;
$o2=$zone->getOffset(new \DateTime("2038-06-06 23:59:00",$zone))/3600;
$o3=$zone->getOffset(new \DateTime("2037-06-06 23:59:00",$zone))/3600;
$o4=$zone->getOffset(new \DateTime("2014-06-06 23:59:00",$zone))/3600;
echo "2079-06-06 23:59:00: ".($o1==2?"Pass":"Fail ($o1)")."\n";
echo "2038-06-06 23:59:00: ".($o2==2?"Pass":"Fail ($o2)")."\n";
echo "2037-06-06 23:59:00: ".($o3==2?"Pass":"Fail ($o3)")."\n";
echo "2014-06-06 23:59:00: ".($o4==2?"Pass":"Fail ($o4)")."\n";

Expected result:
----------------
2079-06-06 23:59:00: Pass
2038-06-06 23:59:00: Pass
2037-06-06 23:59:00: Pass
2014-06-06 23:59:00: Pass


Actual Result:
----------------

2079-06-06 23:59:00: Fail (1)
2038-06-06 23:59:00: Fail (1)
2037-06-06 23:59:00: Pass
2014-06-06 23:59:00: Pass
 [2014-09-19 14:08 UTC] martin dot keckeis1 at gmail dot com
I think the problem is related to here: http://en.wikipedia.org/wiki/Year_2038_problem

Since PHP is still build for x86...

Can you try the x64 build? http://windows.php.net/download/
 [2019-08-17 20:55 UTC] 2 dot josh dot schmidt at gmail dot com
MDT still has a -7 offset when it should be -6. It's correct in versions of php before 5.5.10 and all versions of HHVM.

https://3v4l.org/M7YiI
 [2021-01-08 10:59 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-01-08 10:59 UTC] cmb@php.net
From the PHP manual[1]:

| Please do not use any of the timezones listed here (besides
| UTC), they only exist for backward compatible reasons, and may
| expose erroneous behavior.

Instead use a proper timezone name instead, e.g.
America/Edmonton[2].

[1] <https://www.php.net/manual/en/timezones.others.php>
[2] <https://3v4l.org/MldCo>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC