定制 rflex/period 二次开发

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

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

rflex/period

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);

rflex/period 适用场景与选型建议

rflex/period 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rflex/period 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rflex/period 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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