php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64908 DateTime's constructor accepts time that not exists because of DST
Submitted: 2013-05-23 08:30 UTC Modified: 2013-05-23 18:39 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: istvan dot dani at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: OS X 10.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: istvan dot dani at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-23 08:30 UTC] istvan dot dani at gmail dot com
Description:
------------
Europe/Budapest timezone offset is +1, and +2 in DST.
Transition to DST is at 2013-03-31 01:00:00 UTC/GMT.
According to this, locale time should not exists between 02:00:00 and 03:00:00,
and must not be accepted as valid time.

Test script:
---------------
try {
   $wrong_date = new DateTime("2013-03-31 02:30:00", new DateTimeZone("Europe/Budapest"));
} catch (Exception $e) {
   echo $e->getMessage();
}
print "Wrong date in local timezone: " . $wrong_date->format("Y-m-d H:i:s");
$wrong_date->setTimezone(new DateTimeZone("UTC"));
print "<br />Converting to UTC: " . $wrong_date->format("Y-m-d H:i:s");
$wrong_date->setTimezone(new DateTimeZone("Europe/Budapest"));
print "<br />Converting back to locale timezone: " . $wrong_date->format("Y-m-d H:i:s");


Expected result:
----------------
Get an exception.

Actual result:
--------------
Wrong date in local timezone: 2013-03-31 02:30:00
Converting to UTC: 2013-03-31 01:30:00
Converting back to locale timezone: 2013-03-31 03:30:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-23 17:22 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-05-23 17:22 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP's date time handling auto-corrects wrong date/time values. This is similar to doing:

<?php
$n = new DateTime("2013-04-31");
var_dump( $n );
?>

class DateTime#1 (3) {
  public $date =>
  string(19) "2013-05-01 00:00:00"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(13) "Europe/London"
}
 [2013-05-23 18:17 UTC] istvan dot dani at gmail dot com
Yep. Manual at http://hu1.php.net/manual/en/datetime.construct.php says:
"If an invalid date is specified, then an exception is now thrown. Previously an 
error was emitted."
 [2013-05-23 18:29 UTC] derick@php.net
-Package: Date/time related +Package: Documentation problem
 [2013-05-23 18:29 UTC] derick@php.net
That's wrong, it should say "invalid date *format*". Marking this as a doc issue.
 [2013-05-23 18:31 UTC] aharvey@php.net
-Status: Not a bug +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2013-05-23 18:31 UTC] aharvey@php.net
Reopening.
 [2013-05-23 18:38 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=330341
Log: Make DateTime::__construct()'s changelog clearer on the point that exceptions
are thrown if the date format is invalid, rather than the date itself.

Fixes doc bug #64908 (DateTime's constructor accepts time that not exists
because of DST).
 [2013-05-23 18:39 UTC] aharvey@php.net
-Status: Assigned +Status: Closed -Type: Bug +Type: Documentation Problem
 [2013-05-23 18:39 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 09:01:28 2025 UTC