Bug #78499 [NEW]: [7.2.0+] DateTime on certain dates
| From: | alexanderpas at gmail dot com | Date: | Thu, 05 Sep 2019 22:06:15 +0000 |
| Subject: | Bug #78499 [NEW]: [7.2.0+] DateTime on certain dates | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222579@lists.php.net to get a copy of this message | ||
From: alexanderpas at gmail dot com
Operating system: Any
PHP version: 7.4.0RC1
Package: Date/time related
Bug Type: Bug
Bug description:[7.2.0+] DateTime on certain dates
Description:
------------
When creating a DateTime object using a unix timestamp, the resulting
DateTime object does not represent the same timestamp as it was created
with.
Test script:
---------------
<?php
$tests[] = '0000-01-28 00:00:00 UTC';
$tests[] = '0000-01-29 00:00:00 UTC';
$tests[] = '0000-01-30 00:00:00 UTC';
$tests[] = '0000-01-31 00:00:00 UTC';
$tests[] = '0000-02-01 00:00:00 UTC';
$tests[] = '0000-02-27 00:00:00 UTC';
$tests[] = '0000-02-28 00:00:00 UTC';
$tests[] = '0000-02-29 00:00:00 UTC';
$tests[] = '0000-02-30 00:00:00 UTC'; // intentionally invalid day,
should be the same as the next.
$tests[] = '0000-03-01 00:00:00 UTC';
$tests[] = '0000-03-02 00:00:00 UTC';
foreach ($tests as $test)
{
$timestamp1 = strtotime($test);
$date_time = new DateTime('@' . $timestamp1);
$timestamp2 = $date_time->getTimestamp();
print $timestamp1 . "\n";
print $timestamp2 . "\n";
if ($timestamp1 != $timestamp2)
{
print "timestamps are not equal\n";
}
print_r($date_time);
print "\n";
}
Expected result:
----------------
-62164886400
-62164886400
DateTime Object
(
[date] => 0000-01-28 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164800000
-62164800000
DateTime Object
(
[date] => 0000-01-29 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164713600
-62164713600
DateTime Object
(
[date] => 0000-01-30 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164627200
-62164627200
DateTime Object
(
[date] => 0000-01-31 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164540800
-62164540800
DateTime Object
(
[date] => 0000-02-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162294400
-62162294400
DateTime Object
(
[date] => 0000-02-27 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162208000
-62162208000
DateTime Object
(
[date] => 0000-02-28 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162121600
-62162121600
DateTime Object
(
[date] => 0000-02-29 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162035200
-62162035200
DateTime Object
(
[date] => 0000-03-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162035200
-62162035200
DateTime Object
(
[date] => 0000-03-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62161948800
-62161948800
DateTime Object
(
[date] => 0000-03-02 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
Actual result:
--------------
-62164886400
-62164886400
DateTime Object
(
[date] => 0000-01-28 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164800000
-62164800000
DateTime Object
(
[date] => 0000-01-29 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164713600
-62164800000
timestamps are not equal
DateTime Object
(
[date] => 0000-01-29 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164627200
-62164713600
timestamps are not equal
DateTime Object
(
[date] => 0000-01-30 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62164540800
-62164627200
timestamps are not equal
DateTime Object
(
[date] => 0000-01-31 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162294400
-62162380800
timestamps are not equal
DateTime Object
(
[date] => 0000-02-26 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162208000
-62162294400
timestamps are not equal
DateTime Object
(
[date] => 0000-02-27 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162121600
-62162208000
timestamps are not equal
DateTime Object
(
[date] => 0000-02-28 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162035200
-62162035200
DateTime Object
(
[date] => 0000-03-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62162035200
-62162035200
DateTime Object
(
[date] => 0000-03-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
-62161948800
-62161948800
DateTime Object
(
[date] => 0000-03-02 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
--
Edit bug report at https://bugs.php.net/bug.php?id=78499&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78499&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78499&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78499&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78499&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78499&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78499&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78499&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78499&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78499&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78499&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78499&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78499&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78499&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78499&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78499&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78499&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78499&r=mysqlcfg