Skip to content

Commit

Permalink
Bring back toNative() alias of toDateTimeImmutable()
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Sep 24, 2023
1 parent af68da5 commit 2eee474
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ChronosDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,18 @@ public function toDateTimeImmutable(): DateTimeImmutable
return $this->native;
}

/**
* Returns an `DateTimeImmutable` instance set to this clock time.
*
* Alias of `toDateTimeImmutable()`.
*
* @return \DateTimeImmutable
*/
public function toNative(): DateTimeImmutable
{
return $this->toDateTimeImmutable();
}

/**
* Get a part of the object
*
Expand Down
12 changes: 12 additions & 0 deletions src/ChronosTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,16 @@ public function toDateTimeImmutable(): DateTimeImmutable
$this->getMicroseconds()
);
}

/**
* Returns an `DateTimeImmutable` instance set to this clock time.
*
* Alias of `toDateTimeImmutable()`.
*
* @return \DateTimeImmutable
*/
public function toNative(): DateTimeImmutable
{
return $this->toDateTimeImmutable();
}
}
3 changes: 3 additions & 0 deletions tests/TestCase/ChronosTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,8 @@ public function testToDateTimeImmutable(): void
{
$native = ChronosTime::parse('23:59:59.999999')->toDateTimeImmutable();
$this->assertSame('23:59:59.999999', $native->format('H:i:s.u'));

$native = ChronosTime::parse('23:59:59.999999')->toNative();
$this->assertSame('23:59:59.999999', $native->format('H:i:s.u'));
}
}
3 changes: 3 additions & 0 deletions tests/TestCase/Date/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,8 @@ public function testToDateTimeImmutable(): void
{
$d = ChronosDate::now();
$this->assertSame($d->format('Y-m-d'), $d->toDateTimeImmutable()->format('Y-m-d'));

$d = ChronosDate::now();
$this->assertSame($d->format('Y-m-d'), $d->toNative()->format('Y-m-d'));
}
}

0 comments on commit 2eee474

Please sign in to comment.