note 120046 added to datetime.createfromformat

From: Date: Fri, 14 Oct 2016 12:50:27 +0000
Subject: note 120046 added to datetime.createfromformat
Groups: php.notes 
Request: Send a blank email to php-notes+get-206894@lists.php.net to get a copy of this message
Note a weird and surprising inconsistency in DateTime::createFromFormat() and DateTimeImmutable::createFromFormat() when the format is "U" and these factory-functions are called with a Unix timestamp - in this case, the timezone argument is not only ignored (as per the documentation) but also *NOT APPLIED* the constructed object! In other words, the timezone argument has no effect in this case, at all, which I found pretty surprising. Of course the timezone argument cannot be used in this case to parse the value, since it's a timezone-neutral Unix timestamp, but I was definitely expecting the factory-function to apply the specified timezone to the created object - this is especially surprising when it comes to DateTimeImmutable, since this behavior of the factory-function makes it impossible to create an instance from a timestamp and initialize the timezone with a single call; you will need a subsequent call to setTimezone() discarding the original object. Very strange and confusing design :-* ---- Server IP: 72.52.91.14 Probable Submitter: 193.163.97.225 ---- Manual Page -- http://php.net/manual/en/datetime.createfromformat.php Edit -- https://master.php.net/note/edit/120046 Del: integrated -- https://master.php.net/note/delete/120046/integrated Del: useless -- https://master.php.net/note/delete/120046/useless Del: bad code -- https://master.php.net/note/delete/120046/bad+code Del: spam -- https://master.php.net/note/delete/120046/spam Del: non-english -- https://master.php.net/note/delete/120046/non-english Del: in docs -- https://master.php.net/note/delete/120046/in+docs Del: other reasons-- https://master.php.net/note/delete/120046 Reject -- https://master.php.net/note/reject/120046 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206894) next »