Bug #78778 [Ver->Nab]: DateTime constructor and createFromFormat behaves differently

From: Date: Tue, 06 Apr 2021 19:18:22 +0000
Subject: Bug #78778 [Ver->Nab]: DateTime constructor and createFromFormat behaves differently
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233244@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78778&edit=1

 ID:                 78778
 Updated by:         derick@php.net
 Reported by:        boan at jfmedier dot dk
 Summary:            DateTime constructor and createFromFormat behaves
                     differently
-Status:             Verified
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.2.24
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2019-11-04 11:57:03] cmb@php.net

Well, that doesn't look quite right: <https://3v4l.org/AADtE>.

------------------------------------------------------------------------
[2019-11-04 11:45:38] 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78778&edit=1


Thread (3 messages)

« previous php.bugs (#233244) next »