igor-popravka/ip-time-clock 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

igor-popravka/ip-time-clock

最新稳定版本:v1.1.0

Composer 安装命令:

composer require igor-popravka/ip-time-clock

包简介

PSR-20 Clock implementation based on server's geolocated IP timezone

README 文档

README

Latest Version PHP Version License

A Composer package implementing \Psr\Clock\ClockInterface that returns the accurate current server time based on its geolocation (determined by IP address).

Purpose

This package provides the server's local time considering its timezone, which is automatically resolved via an external time API based on the server’s IP address. Useful when server time is set to UTC but localized time is needed.

Installation

composer require igor-popravka/ip-time-clock

Usage

use IpTimeClock\Clock;
use IpTimeClock\Adapter\TimeIpIoAdapter;
use GuzzleHttp\Client;

// Initialize HTTP client (Guzzle)
$client = new Client();

// Optionally specify an IP address, or null to use server's IP
$ip = null;

// Create adapter
$adapter = new TimeIpIoAdapter($client);

// Create Clock instance
$clock = new Clock($adapter);

// Get current localized time
$currentTime = $clock->now();

echo $currentTime->format('Y-m-d H:i:sP');

Configuration

  • By default, the package uses WorldTimeAPI to determine the timezone from the server's IP address.

  • You can specify a different IP address in the adapter constructor to get the time for a different location.

  • To use another time API provider, implement your own adapter by implementing the TimeApiAdapterInterface.

Testing

The package includes unit tests that mock the time API adapter to verify the correct behavior of the Clock class.

To run tests:

vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-20