php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73489 wrong timestamp when call setTimeZone multi times with UTC offset
Submitted: 2016-11-10 18:48 UTC Modified: 2017-02-12 20:20 UTC
From: fernando dot dias at flechaweb dot com dot br Assigned: jhdxr (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0.13 OS: Ubuntu
Private report: No CVE-ID: None
 [2016-11-10 18:48 UTC] fernando dot dias at flechaweb dot com dot br
Description:
------------
I know that UTC offset is not the better approach to solve timezone issues, even more than region has DST. But in some situations the offset is the only way that you have to manipulate Timezone.

In this situation with you interact with a DateTime object setting TimeZone more the once, it can cause some strange situations, some cases, event timestamp from DateTime appears to be changed.

Test script:
---------------
I got some situations with DateTime and DateTimeZone appears not showing data in the right way.

// example 1 - Timestamp is changing
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
var_dump($datetime->getTimestamp());
$datetime->setTimeZone(new DateTimeZone('-03:00'));
$datetime->setTimeZone(new DateTimeZone('-03:00'));
var_dump($datetime->getTimestamp());

// example 2 - Timestamp keeps if you use getTimestamp() before second setTimeZone() calls
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
var_dump($datetime->getTimestamp());
$datetime->setTimeZone(new DateTimeZone('-03:00'));
$datetime->getTimestamp();
$datetime->setTimeZone(new DateTimeZone('-03:00'));
var_dump($datetime->getTimestamp());


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-11 01:15 UTC] requinix@php.net
-Package: PHP Language Specification +Package: Date/time related
 [2016-11-16 12:02 UTC] jhdxr@php.net
-Summary: DateTimeZone Type 1 UTC offset +Summary: wrong timestamp when call setTimeZone multi times with UTC offset -Status: Open +Status: Assigned -Assigned To: +Assigned To: jhdxr
 [2017-02-12 20:20 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2017-02-12 20:20 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC