zaengle/timezone
Composer 安装命令:
composer require zaengle/timezone
包简介
Helps manage timezones in Laravel.
关键字:
README 文档
README
This package is a fork from Camron Cade modified to fit Zaengle's usage. For more information, read Camron's helpful article on managing timezones in Laravel. The array of timezones and their underlying keys were taken from the repository by tamaspap.
Installation
Recommended installation of this package is through composer. Run the following snippet to add Timezone to your project:
composer require zaengle/timezone
Note: You may jump to Usage if you are on Laravel 5.5+
Once this operation completes, the final step is to add the service provider. Open config/app.php, and add a new item to the service providers array.
'Zaengle\Timezone\TimezoneServiceProvider'
In order to use the Facade, update the aliases array as such:
`Timezone` => `Zaengle\Timezone\Facades\Timezone`,
Now it's ready for use!
Usage
Timezone Convert Helper Functions
The package includes two helper functions that make it easy to deal with displaying and storing timezones, convertFromUTC() and convertToUTC():
Each function accepts two required parameters and a third optional parameter dealing with the format of the returned timestamp.
Timezone::convertFromUTC($timestamp, $timezone, $format);
Timezone::convertToUTC($timestamp, $timezone, $format);
The first parameter accepts a timestamp, the second accepts the name of the timezone that you are converting to/from. The option values associated with the timezones included in the select form builder can be plugged into here as is. Alternatively, you can use any of PHP's supported timezones.
The third parameter is optional, and default is set to 'Y-m-d H:i:s', which is how Laravel natively stores datetimes into the database (the created_at and updated_at columns).
Building a select form
Using the Timezone::toSelectArray() you can build an array of enabled timezones similar to this:
[
"America/Los_Angeles" => "(UTC-08:00) Pacific Time (US & Canada)",
"US/Mountain" => "(UTC-07:00) Mountain Time (US & Canada)",
"US/Central" => "(UTC-06:00) Central Time (US & Canada)",
"US/Eastern" => "(UTC-05:00) Eastern Time (US & Canada)",
]
Then, in your Blade template you have control over formatting:
<select name="timezone" id="timezone">
@foreach(Timezone::toSelectArray() as $key=>$val)
<option value="{{ $val }}" @if($union->timezone === $val) selected @endif>{!! $key !!}</option>
@endforeach
</select>
Customizing timezones
If you want to customize which timezones are displayed in the toSelectArray() method, publish the package configuration file and enable/disable individual timezones:
php artisan vendor:publish --tag=config --provider="Zaengle\Timezone\TimezoneServiceProvider"
Credits
zaengle/timezone 适用场景与选型建议
zaengle/timezone 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.76k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「timezone」 「timezones」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zaengle/timezone 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zaengle/timezone 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zaengle/timezone 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Datetime helpers for timezone handling
A custom Doctine DBAL type to use PHP DateTime objects set to the system's default timezone.
Timezone List Plugin
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
PHP Countries and Currencies
SierraTecnologia common support helpers, contracts, and traits required by various SierraTecnologia packages. Validator functionality, and basic controller included out-of-the-box.
统计信息
- 总下载量: 3.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-15