Is a DateTime
object not bound by its timestamp? Or does getTimestamp() has some kind of side-effect when used on DST change?
Details
When setting the timestamp of a DateTime
object which is on DST
(meaning the formatted time exists both before/after changing the clock) the returned timestamp differs from the set timestamp.
$ php --version
PHP 7.1.3 (cli) (built: Mar 17 2017 16:59:59) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Reproduce
Consider the following php
script:
date_default_timezone_set('Europe/Berlin');
$date = new DateTime();
$set_timestamp = 1319932800;
$date->setTimestamp($set_timestamp);
$get_timestamp = $date->getTimestamp();
fwrite(STDERR, $set_timestamp . "\n"); // 1319932800
fwrite(STDERR, $get_timestamp . "\n"); // 1319936400 **(WHY IS THIS DIFFERENT?)**
Why are the printed values not equal?