tivus/yearly-timespan
Composer 安装命令:
composer require tivus/yearly-timespan
包简介
yearly timspans, timelines, sql-friendly
README 文档
README
Collection of PHP classes to work with yearly repeating timespans.
Heavily using smhgs date-timespan.
Installation
composer require tivus/yearly-timespan dev-master
Classes
The examples shown here are additive (you need the previous ones for the later ones to work).
Yearly Date
Extends the DateTime object. The year is set to 0.
use Timespan\Timespan; use Yearly_Timespan\Yearly_Date; use Yearly_Timespan\Yearly_Timespan; $july = Yearly_Date::createFromFormat( 'd.m', '15.07' ); $feb = Yearly_Date::createFromFormat( 'd.m', '04.02' );
Yearly Timespan
Extends the smgh/timespan Class
$winter_term = new Yearly_Timespan( $july, // start, Yearly_Timespan object. $feb, // end. Yearly_Timespan object. 'Winterterm', // name. 'Term' // type. ); $summer_term = new Yearly_Timespan( $feb, $july, 'Summerterm', 'Term' ); // cast to a Timespan (with a name and type) $current_winter_term = $winter_term->cast_to_year( new \DateTime() ); //check if a (regular) Date is contained by a Yearly_Timespan. if ( $winter_term->contains( \DateTime::createFromFormat( 'd.m.Y', '04.02.2019' ))) { echo '04.02.2019 is in the Winterterm. '; } // check if a (regular) Timespan is overlapped by a Yearly_Timespan. $project_week = new Timespan( \DateTime::createFromFormat( 'd.m.Y', '14.01.2019' ), \DateTime::createFromFormat( 'd.m.Y', '18.01.2019' ) ); if ( $winter_term->overlaps( $project_week ) ){ echo 'The Projekt Week overlaps the Winterterm. '; }
Yearly Timespan Collection
// Create a collection of Yearly_Timespans. $yearly_collection = new Yearly_Timespan_Collection(); // Add Yearly_Timespans to the Collection. $yearly_collection[] = $winter_term; $yearly_collection[] = $summer_term; // Select a Yearly_Timespan (Winterterm in this case) and cast it to a year. $current_term = $yearly_collection->select( new DateTime('2020-01-01') )->get(); // Get the timespan (not yearly) for the Summerterm 2020. $next_term = $yearly_collection->next()->get(); // Create a collection of timespans (not yearly). $timespan_collection = new \Timespan\Collection([ new Timespan( new DateTime( '2015-02-02' ), new DateTime( '2015-07-06' ) ), new Timespan( new DateTime( '2016-06-02' ), new DateTime( '2017-04-06' ) ) ]); /** * Create an array of specific timespans (form the yearly ones) that overlap our new $timespan_collection. * The new \Timespan\Collection Object ($navigation) has a data attribute * that references all Timespans (from the $timespan_collection) * (via an array index), that overlap the newliy create specific timespans ( $navigation ). */ $navigation = $yearly_collection->group_timespans_by_collection( $timespan_collection ); // Get an array of summerterms (specific timespans, not yearly ones) that overlap the given timespan. $many_terms = $yearly_collection->filter('any', 'Summerterm')->make_all_timespans_between( new Timespan( new DateTime('1990-01-01'), new DateTime('2010-01-01') ) );
tivus/yearly-timespan 适用场景与选型建议
tivus/yearly-timespan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.41k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tivus/yearly-timespan 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tivus/yearly-timespan 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-16