gsteel / google-timezone
Google Timezone API 客户端
1.7.0
2023-09-18 21:10 UTC
Requires
- php: ~8.1 || ~8.2 || ~8.3
- fig/http-message-util: ^1.1
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- ext-curl: *
- doctrine/coding-standard: ^12.0.0
- ergebnis/composer-normalize: ^2.37.0
- infection/infection: ^0.27.2
- laminas/laminas-diactoros: ^3.2.0
- php-http/curl-client: ^2.3.0
- php-http/discovery: ^1.19.1
- phpunit/phpunit: ^10.3.4
- psalm/plugin-phpunit: ^0.18.4
- react/child-process: ^0.6.5
- react/http: ^1.9.0
- roave/security-advisories: dev-latest
- vimeo/psalm: ^5.15.0
This package is auto-updated.
Last update: 2024-09-23 04:51:00 UTC
README
简介
提供了一套经过良好测试的接口和价值对象,用于与Google 的时区 API进行交互
安装
唯一支持的安装方法是使用 composer。
此客户端需要一个 PSR-18 Http 客户端 和 PSR-17 工厂实现。这些实现不是 composer 所必需的,因此您需要确保已安装它们,例如
composer require php-http/curl-client laminas/laminas-diactoros gsteel/google-timezone
使用方法
TimeZone API 需要一个Google 的 API 密钥
<?php use DateTimeImmutable; use GSteel\GoogleTimezone\Coordinates; use GSteel\GoogleTimezone\HttpClient; use Http\Client\Curl\Client; use Laminas\Diactoros\RequestFactory; use Laminas\Diactoros\UriFactory; $apiKey = 'Some API Key'; $client = new HttpClient( $apiKey, new Client(), new UriFactory(), new RequestFactory() ); $primeMeridian = '51.47,-0.00'; $referenceDate = DateTimeImmutable::createFromFormat('!Y-m-d', '2020-01-01'); $result = $this->client->fetch( Coordinates::fromString($primeMeridian), $referenceDate ); assert($result->isSuccess()); // true echo $result->timezone()->getName(); // "Europe/London" $result->isReferenceDateDst(); // false echo $result->name(); // "Greenwich Mean Time"
许可证
贡献
…受到欢迎。请确保您的补丁通过 CI :)