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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: heiglandreas@php.net
New email:
PHP Version: OS:

 

 [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: Thu May 30 19:01:32 2024 UTC