note 113261 added to datetime.add
| From: | artaxerxes2 at iname dot com | Date: | Wed, 18 Sep 2013 19:28:35 +0000 |
| Subject: | note 113261 added to datetime.add | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196303@lists.php.net to get a copy of this message | ||
Be careful that the internal timer to your DateTime object can be changed drastically when adding
even 1 second, during the switch from DST to normal.
Consider the following:
<?php
$ts = 1383458399; /* 2013-11-03 01:59:59 in Eastern Saving Time */
$dst = DateTime::createFromFormat('U',$ts, new DateTimeZone('GMT')); /* timezone
is ignored for a unix timestamp, but if we don't put it, php throws warnings */
$dst->setTimeZone(new DateTimeZone('EST5EDT')); /* a timezone effectuating the change
*/
$second = new DateInterval('PT1S'); /* one second */
echo $ts . "\t" . $dst->format("U\tY-m-d H:i:s T") . "\n";
$dst->add($second);
$ts++;
echo $ts . "\t" . $dst->format("U\tY-m-d H:i:s T") . "\n";
/* results:
1383458399 1383458399 2013-11-03 01:59:59 EDT
1383458400 1383462000 2013-11-03 02:00:00 EST
noticed how the second column went from 1383458399 to 1383462000 even though only 1 second was
added?
*/
?>
----
Server IP: 69.147.83.199
Probable Submitter: 199.231.184.141
----
Manual Page -- http://php.net/manual/en/datetime.add.php
Edit -- https://master.php.net/note/edit/113261
Del: integrated -- https://master.php.net/note/delete/113261/integrated
Del: useless -- https://master.php.net/note/delete/113261/useless
Del: bad code -- https://master.php.net/note/delete/113261/bad+code
Del: spam -- https://master.php.net/note/delete/113261/spam
Del: non-english -- https://master.php.net/note/delete/113261/non-english
Del: in docs -- https://master.php.net/note/delete/113261/in+docs
Del: other reasons-- https://master.php.net/note/delete/113261
Reject -- https://master.php.net/note/reject/113261
Search -- https://master.php.net/manage/user-notes.php