PHPackages                             arraypress/google-timezone - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/google-timezone

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/google-timezone
==========================

A PHP library for integrating with the Google Maps Timezone API in WordPress, providing comprehensive timezone detection and information. Features WordPress transient caching and WP\_Error support.

03PHP

Since Jan 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arraypress/google-timezone)[ Packagist](https://packagist.org/packages/arraypress/google-timezone)[ RSS](/packages/arraypress-google-timezone/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Google Maps Timezone API for WordPress
======================================

[](#google-maps-timezone-api-for-wordpress)

A PHP library for integrating with the Google Maps Timezone API in WordPress. This library provides robust timezone detection and information retrieval with support for WordPress transient caching and WP\_Error handling.

Features
--------

[](#features)

- ✅ **Timezone Detection**: Get timezone information for any coordinates
- 🌍 **Global Coverage**: Support for all timezones worldwide
- ⏰ **Time Calculations**: Built-in time offset and DST handling
- 🔄 **Response Parsing**: Clean response object for easy data access
- ⚡ **WordPress Integration**: Native transient caching and WP\_Error support
- 🛡️ **Type Safety**: Full type hinting and strict types
- 📅 **DST Detection**: Automatic daylight saving time detection
- ⌚ **Time Formatting**: Multiple time format options
- 🌐 **Language Support**: Localized timezone names
- 🔍 **Detailed Information**: Access to comprehensive timezone data

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 6.7.1 or later
- Google Maps API key with Timezone API enabled

Installation
------------

[](#installation)

Install via Composer:

```
composer require arraypress/google-timezone
```

Basic Usage
-----------

[](#basic-usage)

```
use ArrayPress\Google\Timezone\Client;

// Initialize client with your API key
$client = new Client( 'your-google-api-key' );

// Get timezone for coordinates
$result = $client->get_timezone( 37.4224764, -122.0842499 );
if ( ! is_wp_error( $result ) ) {
    // Get timezone information
    echo "Timezone: {$result->get_timezone_id() }\n";
    echo "Local Time: {$result->get_datetime()->format( 'Y-m-d H:i:s' ) }\n";
    echo "UTC Offset: {$result->get_formatted_offset() }\n";
}
```

Extended Examples
-----------------

[](#extended-examples)

### Working with Different Time Formats

[](#working-with-different-time-formats)

```
// Get timezone with specific timestamp
$timestamp = strtotime( '2024-12-25 12:00:00' );
$result = $client->get_timezone(
    37.4224764,
    -122.0842499,
    $timestamp
);

if ( ! is_wp_error( $result ) ) {
    $datetime = $result->get_datetime( $timestamp );
    echo "Date: {$datetime->format( 'Y-m-d') }\n";
    echo "Time: {$datetime->format( 'H:i:s') }\n";
    echo "Timezone Name: {$result->get_timezone_name() }\n";
    echo "Abbreviated: {$result->get_abbreviated_name() }\n";
}
```

### DST and Offset Handling

[](#dst-and-offset-handling)

```
$result = $client->get_timezone( 37.4224764, -122.0842499 );
if ( ! is_wp_error( $result ) ) {
    // Check DST status
    if ( $result->is_dst() ) {
        echo "Location is currently observing DST\n";
        echo "DST Offset: {$result->get_dst_offset() } seconds\n";
    }

    // Get various offsets
    echo "Raw UTC Offset: {$result->get_raw_offset() } seconds\n";
    echo "Total Offset: {$result->get_total_offset() } seconds\n";
    echo "Formatted Offset: {$result->get_formatted_offset() }\n";
}
```

### Working with Localized Names

[](#working-with-localized-names)

```
// Get timezone info in French
$result = $client->get_timezone(
    48.8566,  // Paris coordinates
    2.3522,
    null,     // Current time
    'fr'      // French language
);

if ( ! is_wp_error( $result ) ) {
    echo "Nom du fuseau horaire: {$result->get_timezone_name() }\n";
}
```

### Handling Responses with Caching

[](#handling-responses-with-caching)

```
// Initialize with custom cache duration (1 hour = 3600 seconds)
$client = new Client( 'your-api-key', true, 3600 );

// Results will be cached
$result = $client->get_timezone( 37.4224764, -122.0842499 );

// Clear specific cache
$client->clear_cache( 'timezone_37.4224764_-122.0842499' );

// Clear all timezone caches
$client->clear_cache();
```

API Methods
-----------

[](#api-methods)

### Client Methods

[](#client-methods)

- `get_timezone( $latitude, $longitude, $timestamp = null, $language = null )`: Get timezone information
- `clear_cache( $identifier = null )`: Clear cached responses

### Response Methods

[](#response-methods)

#### Timezone Information

[](#timezone-information)

- `get_timezone_id()`: Get the IANA timezone identifier
- `get_timezone_name()`: Get the localized timezone name
- `get_abbreviated_name()`: Get abbreviated timezone name
- `is_valid()`: Check if timezone data is valid
- `is_dst()`: Check if location is observing DST

#### Offset Methods

[](#offset-methods)

- `get_raw_offset()`: Get base UTC offset in seconds
- `get_dst_offset()`: Get DST offset in seconds
- `get_total_offset()`: Get combined UTC and DST offset
- `get_formatted_offset()`: Get human-readable offset string

#### Time Operations

[](#time-operations)

- `get_datetime()`: Get DateTime object for timezone
- `to_array()`: Get all timezone data as array

#### Basic Example

[](#basic-example)

```
use ArrayPress\Google\Timezone\Client;

// Initialize client
$client = new Client( 'your-google-api-key');

// Get timezone for coordinates
$result = $client->get_timezone(37.4224764, -122.0842499);
if ( ! is_wp_error( $result ) ) {
    if ( $result->is_valid() ) {
        // Get basic information
        echo "Timezone ID: {$result->get_timezone_id() }\n";
        echo "Name: {$result->get_timezone_name() }\n";

        // Get current time
        $datetime = $result->get_datetime();
        echo "Local Time: {$datetime->format( 'Y-m-d H:i:s') }\n";

        // Get offset information
        echo "UTC Offset: {$result->get_formatted_offset() }\n";
        if ( $result->is_dst() ) {
            echo "DST is in effect\n";
        }
    }
}
```

Use Cases
---------

[](#use-cases)

- **Local Time Display**: Show accurate local times
- **Event Scheduling**: Convert times between zones
- **Time-based Features**: Schedule operations in local time
- **Global Applications**: Handle international time differences
- **DST Handling**: Accurate seasonal time adjustments
- **Time Formatting**: Display times in local formats
- **Location Services**: Time-aware location features
- **Data Timestamps**: Convert timestamps to local time

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/google-timezone)
- [Issue Tracker](https://github.com/arraypress/google-timezone/issues)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (8 commits)")

### Embed Badge

![Health badge](/badges/arraypress-google-timezone/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-google-timezone/health.svg)](https://phpackages.com/packages/arraypress-google-timezone)
```

###  Alternatives

[ralouphie/mimey

PHP package for converting file extensions to MIME types and vice versa.

3285.9M72](/packages/ralouphie-mimey)[chencha/share

Share links with Laravel

182272.6k](/packages/chencha-share)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)[mvanduijker/laravel-mercure-broadcaster

Mercure broadcaster

16866.5k](/packages/mvanduijker-laravel-mercure-broadcaster)[matomo/network

21897.4k4](/packages/matomo-network)[marc-mabe/php-enum-phpstan

Enum class reflection extension for PHPStan

13817.7k8](/packages/marc-mabe-php-enum-phpstan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
