1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<?php
declare(strict_types=1);
/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\CarbonTimeZone;
use Carbon\CarbonTimeZone;
use Carbon\FactoryImmutable;
use DateTimeImmutable;
use Tests\AbstractTestCase;
class GettersTest extends AbstractTestCase
{
public function testGetAbbr(): void
{
$tz = new CarbonTimeZone('Europe/London');
$this->assertSame('BST', $tz->getAbbr(true));
$this->assertSame('GMT', $tz->getAbbr(false));
}
public function testGetAbbreviatedName(): void
{
$tz = new CarbonTimeZone('Europe/London');
$this->assertSame('BST', $tz->getAbbreviatedName(true));
$this->assertSame('GMT', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Europe/Athens');
$this->assertSame('EEST', $tz->getAbbreviatedName(true));
$this->assertSame('EET', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Pacific/Auckland');
$this->assertSame('NZST', $tz->getAbbreviatedName(true));
$this->assertSame('NZMT', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('America/Toronto');
$this->assertSame('EDT', $tz->getAbbreviatedName(true));
$this->assertSame('EST', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Arctic/Longyearbyen');
$this->assertSame('CEST', $tz->getAbbreviatedName(true));
$this->assertSame('CET', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Atlantic/Faroe');
$this->assertSame('WEST', $tz->getAbbreviatedName(true));
$this->assertSame('WET', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Africa/Ceuta');
$this->assertSame('CEST', $tz->getAbbreviatedName(true));
$this->assertSame('CET', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Canada/Yukon');
$this->assertSame('PDT', $tz->getAbbreviatedName(true));
$this->assertSame('PST', $tz->getAbbreviatedName(false));
$tz = CarbonTimeZone::create('Asia/Pontianak');
$this->assertSame('unknown', $tz->getAbbreviatedName(true));
$this->assertSame('WIB', $tz->getAbbreviatedName(false));
}
public function testToRegionName(): void
{
$summer = new DateTimeImmutable('2024-08-19 12:00 UTC');
$tz = new CarbonTimeZone('Europe/London');
$this->assertSame('Europe/London', $tz->toRegionName($summer));
$tz = new CarbonTimeZone('+05:00');
$this->assertSame('Antarctica/Mawson', $tz->toRegionName($summer));
$tz = new CarbonTimeZone('+05:00');
$this->assertSame('Antarctica/Mawson', $tz->toRegionName($summer));
$factory = new FactoryImmutable();
$factory->setTestNowAndTimezone('2024-01-19 12:00 UTC');
$this->assertSame('-06:00', $factory->now('America/Chicago')->getTimezone()->toOffsetName());
// The 2 assertions below are the current behavior
// but it's questionable, as current time is in winter, -6 should give Chicago
// @TODO Check this deeper
$this->assertSame('America/Chicago', $factory->now('-05:00')->getTimezone()->toRegionName());
$this->assertSame('America/Denver', $factory->now('-06:00')->getTimezone()->toRegionName());
$factory->setTestNowAndTimezone('2024-08-19 12:00 UTC');
$this->assertSame('-05:00', $factory->now('America/Chicago')->getTimezone()->toOffsetName());
$this->assertSame('America/Chicago', $factory->now('-05:00')->getTimezone()->toRegionName());
}
}
|