php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72080 DateTime constructor ignoring Timezone
Submitted: 2016-04-22 18:53 UTC Modified: 2016-05-08 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: matheusmalves at gmail dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 7.0.5 OS: 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matheusmalves at gmail dot com
New email:
PHP Version: OS:

 

 [2016-04-22 18:53 UTC] matheusmalves at gmail dot com
Description:
------------
When I create an object (DateTime), the second parameter (timezone) is ignored and uses UTC. The test script has a comparison with PHP 5.6.

Test script:
---------------
<?php
date_default_timezone_set('UTC');

$dt = new DateTime('2016-04-22 17:00:00', new DateTimeZone('America/Sao_Paulo'));
echo $dt->getTimestamp();

// Result:
// 1461355200 (PHP 5.6.19) -> 04/22/2016 20:00 (UTC)
// 1461344400 (PHP 7.0.5)  -> 04/22/2016 17:00 (UTC)

echo '<br />';

$dt = new DateTime('2016-04-22 20:00:00', new DateTimeZone('UTC'));
$dt->setTimezone(new DateTimeZone('America/Sao_Paulo'));
echo $dt->getTimestamp();

// Result:
// 1461355200 (PHP 5.6.19) -> 04/22/2016 20:00 (UTC)
// 1461355200 (PHP 7.0.5)  -> 04/22/2016 20:00 (UTC)

Expected result:
----------------
1461355200
1461355200

Actual result:
--------------
1461344400
1461355200

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-22 19:18 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2016-04-22 19:18 UTC] requinix@php.net
https://3v4l.org/FEkCA Seems to be working fine.

You're saying that the first half of that *exact* script (though I suggest trying my tweaked version) produces the timestamp 1461344400 in PHP 7?
 [2016-04-22 19:37 UTC] matheusmalves at gmail dot com
-Status: Feedback +Status: Open
 [2016-04-22 19:37 UTC] matheusmalves at gmail dot com
Yes, the result is 1461344400. 

The function phpinfo() return this:
https://i.imgsafe.org/1779570.png
 [2016-04-22 19:40 UTC] matheusmalves at gmail dot com
Using the same code:
1461344400: 2016-04-22 17:00:00 UTC
 [2016-04-26 17:56 UTC] cmb@php.net
-Status: Open +Status: Feedback
 [2016-04-26 17:56 UTC] cmb@php.net
Which versions of the timezonedb are in use?
 [2016-05-08 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 21 02:03:36 2021 UTC