php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81267 Instantiating DateTime with unix timestamps does not set UTC as Timezone
Submitted: 2021-07-16 13:45 UTC Modified: 2021-07-16 13:52 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: heiglandreas@php.net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 8.0.8 OS: 3v4l.org
Private report: No CVE-ID: None
 [2021-07-16 13:45 UTC] 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"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-16 13:52 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2021-07-16 13:52 UTC] derick@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 11:01:32 2024 UTC