NowDerivativesTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonImmutable;
  12. use Carbon\CarbonImmutable as Carbon;
  13. use Tests\AbstractTestCase;
  14. class NowDerivativesTest extends AbstractTestCase
  15. {
  16. public function testNowWithSameTimezone()
  17. {
  18. $dt = Carbon::now('Europe/London');
  19. $dt2 = $dt->nowWithSameTz();
  20. $this->assertSame($dt2->toDateTimeString(), $dt->toDateTimeString());
  21. $this->assertSame($dt2->tzName, $dt->tzName);
  22. Carbon::setTestNow(new Carbon('2017-07-29T07:57:27.123456Z'));
  23. $dt = Carbon::createFromTime(13, 40, 00, 'Africa/Asmara');
  24. $dt2 = $dt->nowWithSameTz();
  25. Carbon::setTestNow();
  26. $this->assertSame($dt->format('H:i'), '13:40');
  27. $this->assertSame($dt2->format('H:i'), '10:57');
  28. $this->assertSame($dt2->tzName, $dt->tzName);
  29. }
  30. }