rovereto/country

Laravel Country

v1.0.0 2022-07-01 16:49 UTC

This package is auto-updated.

Last update: 2024-09-29 06:09:10 UTC


README

在IP2Location中通过国家代码和子区域代码按子区域名称搜索时区的方法

Packagist License Packagist Downloads

安装

使用composer安装此包

composer require rovereto/country

用法

  1. 确定国家和子区域的时区

它接受ISO-3166标准的国家和子区域代码作为参数。

use Rovereto\Country\Concerns\TimeZone;

class MyClass
{
    use TimeZone;
    ...
}

$myClass = new MyClass();
//find time zone for Trentino-Alto Adige, Italy
//return "Europe/Rome"
$myClass->getTimeZone("IT", "IT-32");
//or
$myClass->getTimeZone("IT");

如果国家中有多个时区,当只传递国家代码时,返回首都时区。

use Rovereto\Country\Concerns\TimeZone;

class MyClass
{
    use TimeZone;
    ...
}

$myClass = new MyClass();
//find time zone for Canada
$myClass->getTimeZone("CA");
//return "America/Toronto"
  1. 通过国家代码确定大陆

它接受ISO-3166标准的国家代码作为参数。

use Rovereto\Country\Concerns\Continent;

class MyClass
{
    use Continent;
    ...
}

$myClass = new MyClass();
//find continent for Italy
$myClass->getContinentByCountry("IT");
//return "Europe"

//find continent code for Italy
$myClass->getContinentCodeByCountry("IT");
//return "EU"

//find continent by continent code
$myClass->getContinentByCode("SA");
//return "South America"

但并非所有国家都位于同一大陆(世界的一部分)。俄罗斯位于欧洲和亚洲。第二个可选参数是子区域代码,允许您为俄罗斯的子区域定义大陆。没有参数时,返回“EU”。示例

use Rovereto\Country\Concerns\Continent;

class MyClass
{
    use Continent;
    ...
}

$myClass = new MyClass();
//find continent for Russia
$myClass->getContinentCodeByCountry("RU");
//return "EU"

//find continent for Moscow, Russia
$myClass->getContinentByCountry("RU", "RU-MOW");
//return "Europe"

//find continent for Novosibirskaya oblast', Russia
$myClass->getContinentByCountry("RU", "RU-NVS");
//return "Asia"

//find continent code for Moscow, Russia
$myClass->getContinentCodeByCountry("RU", "RU-MOW");
//return "EU"

//find continent code for Novosibirskaya oblast', Russia
$myClass->getContinentCodeByCountry("RU", "RU-NVS");
//return "AS"
  1. 将IP2Location的子区域名称映射到子区域代码

免费的IP地理位置数据库“IP2Location™ LITE”不返回ISO-3166子区域代码。getSubdivisionCode方法通过国家代码和子区域名称在IP2Location中找到子区域代码。

use Rovereto\Country\Concerns\Subdivision;

class MyClass
{
    use Subdivision;
    ...
}

$myClass = new MyClass();
//find subdivision code for Trentino-Alto Adige, Italy 
$myClass->getSubdivisionCode("IT", "Trentino-Alto Adige");
//return "IT-32"

贡献

请阅读CONTRIBUTING.md以了解我们的行为准则以及向我们提交拉取请求的流程。

版本控制

我们使用语义版本控制进行版本控制。有关可用的版本,请参阅此存储库的标签

变更日志

请参阅变更日志以了解项目的完整历史。

支持

以下支持渠道尽在您的指尖

作者

请参阅参与此项目的贡献者列表

许可证

此项目根据MIT许可证(MIT)(麻省理工学院许可证)授权 - 请参阅LICENSE.md文件以获取详细信息