tanthammar/recurring 问题修复 & 功能扩展

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

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

tanthammar/recurring

最新稳定版本:1.2.1

Composer 安装命令:

composer require tanthammar/recurring

包简介

Laravel Eloquent RRULE tools

README 文档

README

This package adds Eloquent helpers for Simshauns php Recurr package

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require tanthammar/recurring

Important

  • start_at and end_at are expected to be stored in its timezone, not converted to utc in db. The Builder will convert them using the timezone attribute.
  • end_at represents DURATION not last recurrence, src: simshaun/recurr#44

Usage

Let's say you have a DatePattern model in your codebase.

The Builder parses them in combination with the timezone attribute.

Your model must have the following attributes:

protected $casts = [
    'start_at'  => 'immutable_date', //required
    'end_at'    => 'immutable_date', //nullable, represents duration, not last recurrence
    'timezone' => 'string', //required
    'str_rule'  => 'string', //required
    'except_on' => 'array', //array with excluded dates
];

Apply the IsRecurring trait to the model

class DatePattern extends Model
{
    use IsRecurring;
    //...
}

After saving a string rrule to the str_rule field, you'll have access to the following methods. For further information about additional methods see https://github.com/simshaun/recurr

All RecurrenceCollection methods returns max 732 recurrences. (Same as parent simshaun/recurr package). Use the $count parameter to set how many recurrences you want returned.

$dp = App\Models\DatePattern::first();

$dp->recurr()->first(): bool|Recurrence
$dp->recurr()->firstStart(): bool|Carbon
$dp->recurr()->firstEnd(): bool|Carbon

$dp->recurr()->last(): bool|Recurrence
$dp->recurr()->lastStart(): bool|Carbon
$dp->recurr()->lastEnd(): bool|Carbon

$dp->recurr()->next(): bool|Recurrence
$dp->recurr()->nextStart(): bool|Carbon
$dp->recurr()->nextEnd(): bool|Carbon

$dp->recurr()->current(): bool|Recurrence
$dp->recurr()->currentStart(): bool|Carbon
$dp->recurr()->currentEnd(): bool|Carbon

$dp->recurr()->rule(): Rule

$dp->recurr()->all(): RecurrenceCollection, //limited to 732 recurrences

$dp->recurr()->schedule(?int $count): RecurrenceCollection

$dp->recurr()->scheduleBetween(string|DateTime $startDate, string|DateTime $endDate, ?int $count): RecurrenceCollection

$dp->recurr()->scheduleBefore(string|DateTime $beforeDate, ?int $count): RecurrenceCollection

$dp->recurr()->scheduleAfter(string|DateTime $afterDate, ?int $count): RecurrenceCollection

Contributing

Happy for every contribution, make a PR :)

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-20