note 116708 added to datetime.construct
| From: | Rabenschwinge | Date: | Fri, 13 Feb 2015 13:55:02 +0000 |
| Subject: | note 116708 added to datetime.construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201728@lists.php.net to get a copy of this message | ||
Impossible times due to daylight savings are handled by this function in a way similar to impossible
dates, with the difference that this is not an error (i.e. a consequent call to
DateTime::getLastError() yields nothing).
For example:
In the timezone "Europe/Berlin" on Sunday, March 30 2014 there was no 02:30 am, because
that our is being skipped due to daylight savings on that day.
<?php
$tz = new DateTimeZone("Europe/Berlin");
$impossible_time = "2014-03-30T02:30:00";
$date = new DateTime($impossible_time, $tz);
var_dump($date->getLastErrors());
echo "The impossible time '$impossible_time' is interpreted as: " .
$date->format(DateTime::ISO8601) . "\n";
/*
Yields:
array(4) {
'warning_count' =>
int(0)
'warnings' =>
array(0) {
}
'error_count' =>
int(0)
'errors' =>
array(0) {
}
}
The impossible time '2014-03-30T02:30:00' is interpreted as: 2014-03-30T03:30:00+0200
*/
?>
That is similar to how, for example, Febuary 29, 2014 would be handled, which would be interpreted
as March 1, 2014. The difference is, that with the date that would be an error, with the time it is
not.
Ambigous times due to daylight savings are handled as the second possibility. For example the time
2:30 am occurred twice on October 26, 2014 in the timezone "Europe/Berlin".
<?php
$tz = new DateTimeZone("Europe/Berlin");
$ambiguous_time = "2014-10-26T02:30:00";
$date = new DateTime($ambiguous_time, $tz);
echo "The ambiguous time '$ambiguous_time' is interpreted as: " .
$date->format(DateTime::ISO8601) . "\n";
/*
Yields:
The ambiguous time '2014-10-26T02:30:00' is interpreted as: 2014-10-26T02:30:00+0100
*/
?>
Note that "2014-10-26T02:30:00+0200", one hour earlier, would be a correct answer as well.
----
Server IP: 72.52.91.14
Probable Submitter: 87.153.114.67
----
Manual Page -- http://php.net/manual/en/datetime.construct.php
Edit -- https://master.php.net/note/edit/116708
Del: integrated -- https://master.php.net/note/delete/116708/integrated
Del: useless -- https://master.php.net/note/delete/116708/useless
Del: bad code -- https://master.php.net/note/delete/116708/bad+code
Del: spam -- https://master.php.net/note/delete/116708/spam
Del: non-english -- https://master.php.net/note/delete/116708/non-english
Del: in docs -- https://master.php.net/note/delete/116708/in+docs
Del: other reasons-- https://master.php.net/note/delete/116708
Reject -- https://master.php.net/note/reject/116708
Search -- https://master.php.net/manage/user-notes.php