tivus/yearly-timespan 问题修复 & 功能扩展

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

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

tivus/yearly-timespan

最新稳定版本:v2.1.0

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-16