icomefromthenet/schedule 问题修复 & 功能扩展

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

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

icomefromthenet/schedule

Composer 安装命令:

composer require icomefromthenet/schedule

包简介

Helper to manage schedule

README 文档

README

When working with dates and schedules, php has 2 built in helpers DateInteral and DatePeriod using these two classes will get you most of the way. There are a few things to keep in mind.

  1. DatePeriod is not by default and Iterator it use Traversable interface and does not have methods like next,current,rewind.
  2. You will need to match your period to DSL used in DateInterval.
  3. Can't use DatePeriod to represent non liner date intervals, e.g weekdays only.
  4. Still need to design a method to map between a setting and a DateInterval if you want to create it later.
  5. If want to start in middle you need to skip ahead in your own code to given offset.

I wrote this helper to address these shortcomings, I use a builder that will accept a string name and returns an Iterator, during construction you may ask the iterator to skip ahead and I have implement the following common periods.

  1. Yearly
  2. Weekly
  3. Monthly
  4. Fortnightly
  5. Weekday
  6. BiMonthly
  7. Quarterly

Examples

use DateTime;
use IComeFromTheNet\Schedule\ScheduleBuilder;

$start = new DateTime();
$reoccurance = 12;

$builder = new ScheduleBuilder();

return $builder->daily()
        ->start($start)
        ->limit($reoccurance)
        ->skipStart()
        ->build();
        

This create a daily schedule that limit to 12 occursions as where skip the first period. Important to note that there will be 13 occurances, if the start is not skipped. This is a feature of PHP DatePeriod when setting a limit using an integer the number is re-occurance after the start. Total occurances is start + re-occurances (limit).

use DateTime;
use IComeFromTheNet\Schedule\ScheduleBuilder;


$start = new DateTime();
$reoccurance = 12;

$builder = new ScheduleBuilder();

return $builder->monthly()
        ->start($start)
        ->limit($reoccurance)
        ->offset(4)
        ->build();

This will return a monthly schedule 4 occurances in. If the starting month was August the first starting value at december. Using a LimitIterator to restrict the result set.

use DateTime;
use IComeFromTheNet\Schedule\ScheduleBuilder;


$start = new DateTime();
$reoccurance = 12;

$builder = new ScheduleBuilder();

return $builder->create('monthly')
        ->start($start)
        ->limit($reoccurance)
        ->build();

This will return a monthly schedule, the rule is defined using a string and not direct method call.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固