ivan-berger / server-timezone
Get server time based on IP timezone
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ivan-berger/server-timezone
Requires
- php: ^8.4
- ext-curl: *
Requires (Dev)
- mockery/mockery: ^1.6
- pestphp/pest: ^3.7
- pestphp/pest-plugin: ^3.0
README
This is a test project to retrieve the server's current time based on the provided IP address.
Description
The project includes a ServerTimeZone
class that provides functionality to get the current server time using the IP address. It uses an external time API to fetch the current time and timezone information.
Installation
- Clone the repository:
git clone https://github.com/rchitector/ServerTimeZone.git
- Navigate to the project directory:
cd ServerTimeZone
- Install the dependencies using Composer:
composer install
Usage
To get the current server time based on the provided IP address, you can use the ServerTimeZone
class:
use IvanBerger\ServerTimeZone\IPProvider; use IvanBerger\ServerTimeZone\TimeServiceException; use IvanBerger\ServerTimeZone\ServerTimeZone; try { $ipProvider = new IPProvider(); $ip = $ipProvider->detectIP(); echo 'Current IP detected: ' . $ip . PHP_EOL; $serverTime = new ServerTimeZone($ip); $cdt = $serverTime->getCurrentDateTime(); echo 'Current server time detected: ' . $cdt->format('Y-m-d H:i:s P'); } catch (TimeServiceException $e) { echo 'Error: '.$e->getMessage(); }