arraypress/wp-timezones
Composer 安装命令:
composer require arraypress/wp-timezones
包简介
A lightweight WordPress library for working with timezone data and utilities.
README 文档
README
A lightweight PHP library for working with timezone data in WordPress. Simple, static methods for timezone identifiers, regions, offsets, and utilities.
Features
- 🕐 Complete PHP timezone list (400+ timezones)
- 🌍 Region grouping and filtering
- 🎯 Simple static API - no instantiation needed
- 📝 Multiple output formats for dropdowns
- 🔍 Search and validation utilities
- ⏰ UTC offset calculation and formatting
- 🎨 Gutenberg/React compatible formats
Installation
composer require arraypress/wp-timezones
Basic Usage
use ArrayPress\Timezones\Timezones; // Get all timezones $timezones = Timezones::all(); // Returns: ['Africa/Abidjan', 'Africa/Accra', ...] // Get formatted label $label = Timezones::get_label( 'America/New_York' ); // "America/New York" // Check if timezone exists if ( Timezones::exists( 'Europe/London' ) ) { // Valid timezone } // Validate and sanitize user input $timezone = Timezones::sanitize( $_POST['timezone'] ); // "America/New_York" or null
Dropdown Options
// Gutenberg/React format (value/label) $options = Timezones::get_value_label_options(); // Returns: [['value' => 'America/New_York', 'label' => 'America/New York'], ...] // Key/value format $options = Timezones::get_key_value_options(); // Returns: ['America/New_York' => 'America/New York', ...] // With empty option $options = Timezones::get_value_label_options( true, '— Select Timezone —' ); // With UTC offset in labels $options = Timezones::get_options_with_offset(); // Returns: [['value' => 'America/New_York', 'label' => '(UTC-05:00) America/New York'], ...] // Grouped by region $grouped = Timezones::get_grouped_options(); // Returns: ['America' => [['value' => 'America/New_York', 'label' => 'New York'], ...], ...]
UTC Offsets
// Get offset in seconds $offset = Timezones::get_offset( 'America/New_York' ); // -18000 // Get formatted offset string $offset = Timezones::get_offset_string( 'America/New_York' ); // "-05:00" $offset = Timezones::get_offset_string( 'Asia/Kolkata' ); // "+05:30"
Regions
// Get region from timezone $region = Timezones::get_region( 'America/New_York' ); // "America" // Get city from timezone $city = Timezones::get_city( 'America/New_York' ); // "New York" // Get all regions $regions = Timezones::get_regions(); // Returns: ['Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'] // Get timezones by region $american = Timezones::get_by_region( 'America' ); // Get region options for dropdown $options = Timezones::get_region_options();
Search
// Search by identifier $results = Timezones::search( 'york' ); // Returns: ['America/New_York'] // Search with limit $results = Timezones::search( 'america', 5 );
Helper Functions
Global functions are available for convenience:
// Get formatted label $label = get_timezone_label( 'America/New_York' ); // "America/New York" // Get UTC offset $offset = get_timezone_offset( 'America/New_York' ); // -18000 // Get formatted offset string $offset = get_timezone_offset_string( 'America/New_York' ); // "-05:00" // Get region $region = get_timezone_region( 'America/New_York' ); // "America" // Get dropdown options $options = get_timezone_options(); // Get all regions $regions = get_timezone_regions(); // Validate timezone if ( is_valid_timezone( 'Europe/London' ) ) { // Valid } // Sanitize user input $timezone = sanitize_timezone( $_POST['timezone'] );
API Reference
| Method | Description | Return |
|---|---|---|
all() |
Get all timezones | array |
exists($timezone) |
Check if exists | bool |
sanitize($timezone) |
Validate/sanitize | ?string |
get_label($timezone) |
Get formatted label | string |
get_region($timezone) |
Get region | string |
get_city($timezone) |
Get city/location | string |
get_offset($timezone) |
Get UTC offset (seconds) | ?int |
get_offset_string($timezone) |
Get formatted offset | string |
get_regions() |
Get all regions | array |
get_by_region($region) |
Timezones in region | array |
search($term, $limit) |
Search timezones | array |
get_options($format, $empty, $label) |
Get dropdown options | array |
get_key_value_options($empty, $label) |
Key/value format | array |
get_value_label_options($empty, $label) |
Value/label format | array |
get_options_with_offset($empty, $label) |
Options with UTC offset | array |
get_grouped_options() |
Grouped by region | array |
get_region_options($empty, $label) |
Region dropdown options | array |
Requirements
- PHP 7.4 or higher
- WordPress 6.0 or higher
License
GPL-2.0-or-later
arraypress/wp-timezones 适用场景与选型建议
arraypress/wp-timezones 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「timezone」 「datetime」 「wp」 「utc」 「regions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-timezones 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-timezones 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-timezones 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Time provider, providing consistent current date, time, datetime and timezone across the request.
Adds the EDTF data type to Wikibase
Datetime helpers for timezone handling
A custom Doctine DBAL type to use PHP DateTime objects set to the system's default timezone.
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-01-22