定制 rflex/period 二次开发

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

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

rflex/period

最新稳定版本:0.6.5

Composer 安装命令:

composer require rflex/period

包简介

Customized library for comparing periods easily. This is an extension of Carbon\Period.

README 文档

README

Period is a library that extends CarbonPeriod to supply new customized methods.

You can find the CarbonPeriod documentation here.

Installation & Usage

composer require rflex/period

Import the class:

use Rflex\Period;
use Rflex\Event; // Extension of the Carbon class.

Testing

PHPUnit

./vendor/phpunit/phpunit/phpunit

PHPStan

./vendor/bin/phpstan analyse

Available methods

addDay() and addDays($days): void

Add one or a number of days to the period.

$period->addDay(true, false); // Add a day to the start of the period.
$period->addDays(5, true, false); // Add five days to the start of the period.

subDay() and subDays($days): void

Subtract one or a number of days to the period.

$period->subDay(false, true); // Subtract a day to the end of the period.
$period->subDays(3, false, true); // Subtract three days to the end of the period.

getSeconds(): int

Returns the total number of seconds of the period.

$period->getSeconds();

getMinutes(): int

Returns the total number of minutes of the period.

$period->getMinutes();

getHours(): int

Returns the total number of hours of the period.

$period->getHours();

union($period, $intersects): Period

Returns a new Period that is the sum of another two Periods. By default it will sum two periods without validating if they intersect. With the $intersects in true you can specify that you only need to sum two periods that intersect with each other.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->union($period2); // Returns a new unified Period.

intersection($period): Period

Get the shared period between two other periods.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$intersection = $period->intersection($period2); // Returns a new intersected Period.

intersects($period): bool

Checks if a period intersects with another.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$period->intersects($period2); // Returns true.

difference($period): array|null

Returns the difference between two Periods. This function can return more than one Period if the original Period was cut in different pieces. [totalLengthInSeconds, 'periods' => []]

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->difference($period2); // Returns an array.

differenceWithEvent($event, $point): int

Returns the difference in seconds between a Period and an Event. The comparison is between the Event and a point of the Period. 0 = start, 1 = end.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$event = Event::create(carbon::now());
$seconds = $period->differenceWithEvent($event); // Returns the difference between the two in seconds.

setLengthInSeconds($seconds): void

Set the length of the period in seconds from the start.

$period->setLengthInSeconds(3600);

setLengthInMinutes($minutes): void

Set the length of the period in minutes from the start.

$period->setLengthInMinutes(700);

setLengthInHours($hours): void

Set the length of the period in hours from the start.

$period->setLengthInHours(48);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-12-27