Skip to content

Commit

Permalink
Implement DateTimeImmutable::createFromMutable
Browse files Browse the repository at this point in the history
Summary:Closes #6805
Closes #6846

Reviewed By: JoelMarcey

Differential Revision: D2957341

Pulled By: JoelMarcey

fb-gh-sync-id: caf85837f4d4320d5b2df0839d6a7b34196a850c
shipit-source-id: caf85837f4d4320d5b2df0839d6a7b34196a850c
  • Loading branch information
SiebelsTim authored and Hhvm Bot committed Feb 27, 2016
1 parent dbc4523 commit 526ebfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hphp/system/php/date/datetimeimmutable.php
Expand Up @@ -99,6 +99,12 @@ public static function createFromFormat(
return $out;
}

public static function createFromMutable(DateTime $datetime) {
$out = new DateTimeImmutable();
$out->data = clone $datetime;
return $out;
}

public static function getLastErrors(): array {
return DateTime::getLastErrors();
}
Expand Down
@@ -0,0 +1,9 @@
<?php
$current = "2014-03-02 16:24:08";

$i = DateTimeImmutable::createFromMutable( date_create( $current ) );
var_dump( $i );

$i = DateTimeImmutable::createFromMutable( date_create_immutable( $current ) );
var_dump( $i );
?>
@@ -0,0 +1,13 @@
object(DateTimeImmutable)#%d (1) {
["data":"DateTimeImmutable":private]=>
object(DateTime)#%d (3) {
["date"]=>
string(26) "2014-03-02 16:24:08.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(%s) "%s"
}
}

Catchable fatal error: Argument 1 passed to DateTimeImmutable::createFromMutable() must be an instance of DateTime, DateTimeImmutable given in %s/DateTimeImmutable_createFromMutable.php on line 7

0 comments on commit 526ebfa

Please sign in to comment.