Bug #81267 [Opn->Nab]: Instantiating DateTime with unix timestamps does not set UTC as Timezone
| From: | derick@php.net | Date: | Fri, 16 Jul 2021 13:52:51 +0000 |
| Subject: | Bug #81267 [Opn->Nab]: Instantiating DateTime with unix timestamps does not set UTC as Timezone | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235083@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81267&edit=1
ID: 81267
Updated by: derick@php.net
Reported by: heiglandreas@php.net
Summary: Instantiating DateTime with unix timestamps does not
set UTC as Timezone
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: 3v4l.org
PHP Version: 8.0.8
Block user comment: N
Private report: N
New Comment:
This is for BC reasons, and this issue tracker is also not the right places, as this is parsed by
timelib: https://github.com/derickr/timelib/blob/master/parse_date.re#L1126-L1129
Previous Comments:
------------------------------------------------------------------------
[2021-07-16 13:45:41] heiglandreas@php.net
Description:
------------
Currently creating a new DateTime(Immutable) Object using a timestamp does set the timezone as
+00:00 (Type 1).
Expected outcome would be to have the timestamp be set to UTC (type 3).
Why?
According to https://en.wikipedia.org/wiki/Unix_time the unix
timestamp is always thought to be a representation of a DateTime in UTC. Having the timezone set to
a simple offset does not reflect that. Even though the Unix timestamp has its own way of handling
leap seconds and even though there are thoughts on coupling the unix timestamp to a (not yet
generally used) "International time" (which would be UTC without leap seconds) the
timestamp is generally considered to be a UTC representation, not just of offset +00:00.
See :
* https://en.wikipedia.org/wiki/Unix_time
* https://3v4l.org/f7bBe
Test script:
---------------
<?php
$f = new DateTimeImmutable('@1234567');
var_dump($f->getTimezone());
Expected result:
----------------
object(DateTimeZone)#2 (2) {
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
Actual result:
--------------
object(DateTimeZone)#2 (2) {
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81267&edit=1