php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78778 DateTime constructor and createFromFormat behaves differently
Submitted: 2019-11-04 11:45 UTC Modified: 2021-04-06 19:18 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: boan at jfmedier dot dk Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.2.24 OS:
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: boan at jfmedier dot dk
New email:
PHP Version: OS:

 

 [2019-11-04 11:45 UTC] boan at jfmedier dot dk
Description:
------------
I would expect that the factory method createFromFormat should work like the constructor parameter. 

Test script:
---------------
$date = new DateTimeImmutable('2019-11-01T12:12:40.8859136+00:00');

var_dump($date);

$date = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, '2019-11-01T12:12:40.8859136+00:00');

var_dump($date);

Expected result:
----------------
object(DateTimeImmutable) {
  ["date"]=>
  string(26) "2019-11-01 12:12:40.885913"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}

object(DateTimeImmutable) {
  ["date"]=>
  string(26) "2019-11-01 12:12:40.885913"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}

Actual result:
--------------
object(DateTimeImmutable) {
  ["date"]=>
  string(26) "2019-11-01 12:12:40.885913"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}

bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-04 11:57 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-11-04 11:57 UTC] cmb@php.net
Well, that doesn't look quite right: <https://3v4l.org/AADtE>.
 [2020-01-20 17:11 UTC] girgias@php.net
-Assigned To: +Assigned To: derick
 [2021-04-06 19:18 UTC] derick@php.net
-Status: Verified +Status: Not a bug
 [2021-04-06 19:18 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

The 'v' in DateTimeInterface::RFC3339_EXTENDED ('Y-m-d\TH:i:s.vP') only accepts microseconds. The constructor is more lenient and allows for additional digits to be parsed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 20:01:30 2025 UTC