Edit report at https://bugs.php.net/bug.php?id=68549&edit=1
ID: 68549
Updated by: heiglandreas@php.net
Reported by: mfaust at usinternet dot com
Summary: Timezones and offsets are not properly used when
working with dates
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.6.3
Block user comment: N
Private report: N
New Comment:
It might indeed be the case that there are testcases already available.
Previous Comments:
------------------------------------------------------------------------
[2021-11-09 07:33:49] roel dot harbers at on2it dot net
Thanks for the reply :)
I'm looking at fixing it, and it seems there might already be test cases for it?
EXPECTED FAILED TEST SUMMARY
---------------------------------------------------------------------
DateTime::add() -- fall type2 type3 [ext/date/tests/DateTime_add-fall-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::add() -- fall type3 type2 [ext/date/tests/DateTime_add-fall-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::add() -- fall type3 type3 [ext/date/tests/DateTime_add-fall-type3-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::add() -- spring type2 type3 [ext/date/tests/DateTime_add-spring-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::add() -- spring type3 type2 [ext/date/tests/DateTime_add-spring-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::add() -- spring type3 type3 [ext/date/tests/DateTime_add-spring-type3-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- fall type2 type3 [ext/date/tests/DateTime_diff-fall-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- fall type3 type2 [ext/date/tests/DateTime_diff-fall-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- fall type3 type3 [ext/date/tests/DateTime_diff-fall-type3-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- spring type2 type3 [ext/date/tests/DateTime_diff-spring-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- spring type3 type2 [ext/date/tests/DateTime_diff-spring-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::diff() -- spring type3 type3 [ext/date/tests/DateTime_diff-spring-type3-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- fall type2 type3 [ext/date/tests/DateTime_sub-fall-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- fall type3 type2 [ext/date/tests/DateTime_sub-fall-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- fall type3 type3 [ext/date/tests/DateTime_sub-fall-type3-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- spring type2 type3 [ext/date/tests/DateTime_sub-spring-type2-type3.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- spring type3 type2 [ext/date/tests/DateTime_sub-spring-type3-type2.phpt] XFAIL
REASON: Various bugs exist
DateTime::sub() -- spring type3 type3 [ext/date/tests/DateTime_sub-spring-type3-type3.phpt] XFAIL
REASON: Various bugs exist
Bug #52480 (Incorrect difference using DateInterval) [ext/date/tests/bug52480.phpt] XFAIL REASON:
See https://bugs.php.net/bug.php?id=52480
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, bd2)
[ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-bd2.phpt] XFAIL REASON: Still not quite
right
RFC: DateTime and Daylight Saving Time Transitions (zone type 3, fs)
[ext/date/tests/rfc-datetime_and_daylight_saving_time-type3-fs.phpt] XFAIL REASON: Still not quite
right
=====================================================================
(on branch PHP-7.4)
------------------------------------------------------------------------
[2021-11-08 11:28:18] heiglandreas@php.net
@ roel dot harbers at on2it dot net
There is a response in sight, which is the - already in the initial bugreport mentionend - RFC
(https://wiki.php.net/rfc/datetime_and_daylight_saving_time)
The RFC has been accepted but so far not been implemented.
As PHP is an OpenSource Project: Feel free to create the appropriate PullRequest to fix this issue.
------------------------------------------------------------------------
[2021-11-08 11:04:03] roel dot harbers at on2it dot net
Still going wrong in php 7.4.3:
<?php
// $originalTimestamp = 1636275599; // ok
$originalTimestamp = 1636275600; // wrong (- 3600 sec)
// $originalTimestamp = 1636279199; // wrong (- 3600 sec)
// $originalTimestamp = 1636279200; // ok
$tz = new DateTimeZone('America/Los_Angeles');
// this fails in the opposite way:
// $originalTimestamp = 1635638399; // ok
// $originalTimestamp = 1635638400; // wrong (+ 3600 sec)
// $originalTimestamp = 1635641999; // wrong (+ 3600 sec)
// $originalTimestamp = 1635642000; // ok
// $tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('now', $tz);
print_r($dt);
printf("now ISO8601 format: %s\n", $dt->format(DateTimeInterface::ISO8601));
printf("now timestamp: %d\n", $dt->getTimestamp());
printf("\nsetting timestamp to %d:\n\n", $originalTimestamp);
$dt->setTimestamp($originalTimestamp);
$actualTimestamp = $dt->getTimestamp();
print_r($dt);
printf("DateTime object's ISO8601 format: %s\n",
$dt->format(DateTimeInterface::ISO8601));
printf("DateTime object's UNIX timestamp: %d\n", $actualTimestamp);
printf("difference (should be 0): %d\n", $actualTimestamp - $originalTimestamp);
?>
How is this bug seven years old with not even a response in sight...
------------------------------------------------------------------------
[2021-10-01 16:09:59] cmb@php.net
Related To: Bug #73138
------------------------------------------------------------------------
[2015-12-30 22:07:41] mj1856 at hotmail dot com
As seen here: http://stackoverflow.com/q/34533604/634824
$date = new \DateTime("now", new \DateTimeZone("UTC"));
$date->setTimestamp(1540686600);
echo $date->getTimestamp() . "\n"; //1540686600
echo $date->format('c') . "\n"; //2018-10-28T00:30:00+00:00
This is wrong, as the timestamp corresponds to 1:30:00+01:00
Additionally,
$date->setTimezone(new \DateTimeZone("Europe/London"));
echo $date->getTimestamp() . "\n"; //1540690200
This is really bad, as changing the timezone should NEVER change the timestamp.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=68549
--
Edit this bug report at https://bugs.php.net/bug.php?id=68549&edit=1