php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62704 3rd argument of DateTime::createFromFormat doesn't work
Submitted: 2012-07-31 11:35 UTC Modified: 2012-08-01 08:36 UTC
From: jachym dot tousek at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.5 OS: Windows 7 x64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jachym dot tousek at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-31 11:35 UTC] jachym dot tousek at gmail dot com
Description:
------------
I thought these two commands are equal:
DateTime::createFromFormat('U', 1343730289, new DateTimeZone("Europe/Prague"))
DateTime::createFromFormat('U', 1343730289)->setTimeZone(new DateTimeZone("Europe/Prague"))

However they aren't. If that behaviour is correct (I'm unsure) can you explain why are they different?

Test script:
---------------
var_export(
DateTime::createFromFormat('U', 1343730289)->setTimeZone(new DateTimeZone("Europe/Prague"))->getTimeZone()->getName() === DateTime::createFromFormat('U', 1343730289, new DateTimeZone("Europe/Prague"))->getTimeZone()->getName()
);

Expected result:
----------------
true

Actual result:
--------------
false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-01 08:36 UTC] salathe@php.net
For the first "command" please see the note on the DateTime::createFromFormat() 
manual page [1] which states:

  The timezone parameter and the current timezone are ignored
  when the time parameter either contains a UNIX timestamp
  (e.g. 946684800) or specifies a timezone 
  (e.g. 2010-01-28T15:00:00+02:00).

[1] http://php.net/manual/en/datetime.createfromformat.php
 [2012-08-01 08:36 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 03:01:28 2024 UTC