定制 dcarbone/gotime 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dcarbone/gotime

最新稳定版本:v0.6.1

Composer 安装命令:

composer require dcarbone/gotime

包简介

Golang-like time class(es) for PHP 8.0+

README 文档

README

Golang-like time class(es) for PHP 8.1+

Tests

Desc

The goal of this lib is to achieve near-enough (as determined by me) api equivalency in PHP to the GoLang Time package, as basically it is just better than PHP's.

Classes

Duration

The Duration class is designed to emulate the golang time.Duration type.

There are 2 ways to construct a Duration class:

use \DCarbone\Go\Time;

$d = new Time\Duration(5 * Time::Second);
// produces a Duration with an internal value of 5e9;

$d = Time::ParseDuration('5s');
// produces a Duration with an internal value of 5e9;

Internally the "duration" is represented as an integer, allow for much fun.

Serialization

Assuming $dt = new Time\Duration(5 * Time::Second);:

Type Exec Output
JSON echo json_encode($dt); 5000000000
string echo (string)$dt; 5s;

DateInterval

DateInterval pretty much sucks. I have created my own DateInterval and IntervalSpec classes to help alleviate this.

These provide Duration the ability to create an interval for use with the standard DateTime::add and DateTime::sub methods as such:

$dt = new \DateTime();
echo "{$dt->format('H:i:s')}\n";

$d = new Time\Duration(5 * Time::Second);
$dt->add($d->DateInterval());
echo "{$dt->format('H:i:s')}\n";

// 16:03:37
// 16:03:42

Time

The Time class is designed to BARELY emulate the golang time.Time type. It's basically DateTime with stuff on it. I consider it to be in a "beta" state.

There are 2 basic ways to construct a Time class:

use DCarbone\Go\Time;

// Returns an instance of Time\Time with an internal time of the unix epoch 
$t = Time::New();

// Returns an instance of Time\Time with an internal time of whenever you constructed it. 
$t = Time::Now();

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-11