zaengle/timezone 问题修复 & 功能扩展

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

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

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

Camron Cade

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 zaengle/timezone 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 37
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-15