定制 myparcelcom/timezone-resolver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

myparcelcom/timezone-resolver

Composer 安装命令:

composer require myparcelcom/timezone-resolver

包简介

Resolves a local timezone from address data using the GeoNames API.

README 文档

README

A lightweight PHP package that resolves an IANA timezone identifier from address data, using the GeoNames API.

Requirements

Installation

composer require myparcelcom/timezone-resolver

Usage

use MyParcelCom\TimezoneResolver\GeoNames;

$resolver = new GeoNames(username: 'your-geonames-username');

$timezone = $resolver->getTimezone(
    countryCode: 'NL',
    postalCode: '1043NT',
    city: 'Amsterdam',
);

// 'Europe/Amsterdam'

Method signature

public function getTimezone(
    string $countryCode,
    ?string $postalCode = null,
    ?string $city = null,
): ?string
  • Tries to resolve by postalCode first.
  • Falls back to city if the postal code yields no results.
  • Returns null if no timezone can be determined.

Using the interface

Depend on TimezoneResolverInterface instead of the concrete class to keep your code decoupled:

use MyParcelCom\TimezoneResolver\TimezoneResolverInterface;

class MyService
{
    public function __construct(
        private readonly TimezoneResolverInterface $timezoneResolver,
    ) {}
}

Configuration

The GeoNames username is passed directly to the constructor. In a Laravel application, bind the interface in a service provider:

use MyParcelCom\TimezoneResolver\GeoNames;
use MyParcelCom\TimezoneResolver\TimezoneResolverInterface;

$this->app->bind(
    TimezoneResolverInterface::class,
    fn () => new GeoNames(config('services.geonames.username')),
);
// config/services.php
'geonames' => [
    'username' => env('GEONAMES_USERNAME'),
],

Testing

composer install
vendor/bin/phpunit

License

Proprietary — © MyParcel.com

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固