From d42febcf49b38d22fc5035a52c9f35269cea9d66 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Fri, 9 Mar 2018 09:56:23 +0100 Subject: [PATCH 1/2] Keep resolveCarbon protected --- src/Carbon/Carbon.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Carbon/Carbon.php b/src/Carbon/Carbon.php index a714e47004..bec7d29734 100644 --- a/src/Carbon/Carbon.php +++ b/src/Carbon/Carbon.php @@ -456,16 +456,6 @@ public static function now($tz = null) return new static(null, $tz); } - /** - * Returns a present instance in the same timezone. - * - * @return static - */ - public function nowWithSameTz() - { - return static::now($this->getTimezone()); - } - /** * Create a Carbon instance for today. * @@ -807,14 +797,24 @@ public function copy() return clone $this; } + /** + * Returns a present instance in the same timezone. + * + * @return static + */ + public function nowWithSameTz() + { + return static::now($this->getTimezone()); + } + /** * Return the Carbon instance passed through or a copy in the same timezone. * * @param \Carbon\Carbon|null $date * - * @return \Carbon\Carbon + * @return static */ - public function resolveCarbon(self $date = null) + protected function resolveCarbon(self $date = null) { return $date ?: $this->nowWithSameTz(); } From d8bb5dd1be3c8442d05ac54cadfd5c5c2bc5d039 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Fri, 9 Mar 2018 10:21:20 +0100 Subject: [PATCH 2/2] Remove resolveCarbon tests and add test for nowWithSameTz --- tests/Carbon/NowDerivativesTest.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/Carbon/NowDerivativesTest.php b/tests/Carbon/NowDerivativesTest.php index f9e61cf35b..4fd1c87eae 100644 --- a/tests/Carbon/NowDerivativesTest.php +++ b/tests/Carbon/NowDerivativesTest.php @@ -20,22 +20,17 @@ public function testNowWithSameTimezone() { $dt = Carbon::now('Europe/London'); $dt2 = $dt->nowWithSameTz(); + $this->assertSame($dt2->toDateTimeString(), $dt->toDateTimeString()); $this->assertSame($dt2->tzName, $dt->tzName); - } - public function testResolveCarbon() - { - $dt = Carbon::now(); - $dt2 = Carbon::yesterday(); - $this->assertInstanceOfCarbon($dt->resolveCarbon($dt2)); - $this->assertSame($dt2, $dt->resolveCarbon($dt2)); - } + Carbon::setTestNow(new Carbon('2017-07-29T07:57:27.123456Z')); + $dt = Carbon::createFromTime(13, 40, 00, 'Africa/Asmara'); + $dt2 = $dt->nowWithSameTz(); + Carbon::setTestNow(); - public function testResolveCarbonNull() - { - $dt = Carbon::now(); - $this->assertInstanceOfCarbon($dt->resolveCarbon(null)); - $this->assertSame($dt->toDateTimeString(), $dt->resolveCarbon(null)->toDateTimeString()); + $this->assertSame($dt->format('H:i'), '13:40'); + $this->assertSame($dt2->format('H:i'), '10:57'); + $this->assertSame($dt2->tzName, $dt->tzName); } }