iserv/zeit 问题修复 & 功能扩展

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

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

iserv/zeit

最新稳定版本:v1.3

Composer 安装命令:

composer require iserv/zeit

包简介

An all purpose library for date and time handling.

README 文档

README

Usage

Zeit and Clock

The Zeit library offers you some assitance in handling date and time related information. One the one side we have the Zeit util and a Clock which can be asked for the current time. It will use the system clock by default, but a fixed value can be injected for testing.

use IServ\Library\Zeit\Clock\FixedClock;
use IServ\Library\Zeit\Zeit;

$now = Zeit::now();
printf("It is %s o'clock", $now->format('H'));

Zeit::setClock(FixedClock::fromString('2021-04-23 12:00:00'));

$now = Zeit::now();
printf("It is %s o'clock", $now->format('H'));
 // Will print 12 o'clock

The Clock is an extension of the PSR-20: Clock adding the option to usleep the clock so that you can do time elapsing testing, too.

Date and Time

The library also offers Date and Time domain objects. These can be used to model only relevant data where you'd normally rely on PHP's built-in DateTime objects. The models can be converted to DateTime objects for further processing, but keep in mind that PHP will add the missing parts for you.

use IServ\Library\Zeit\Date;
use IServ\Library\Zeit\Time;

$date = Date::fromParts(2021, 4, 23);
echo $date->getValue();
// will print the normalized string representation "2021-04-23"

$time = Time::fromParts(10, 37); // The third parameter for seconds is optional and defaults to zero 
echo $time->getValue();
// will print the normalized string representation "10:37:00"

// You can merge a Date and a Time to \DateTimeImmutable
$dateTime = $date->withTime($time);
echo $dateTime->format('Y:m:d H:i:s');
// will print "2021-04-23 10:37:00"

The real power of Date and Time can be leveraged with the ZeitBridge component which integrates the library into your Doctrine/Symfony project and allows to map the Zeit models into entities and forms directly.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-23