tanthammar/recurring

Laravel Eloquent RRULE 工具

1.1.0 2024-03-14 11:02 UTC

This package is auto-updated.

Last update: 2024-09-14 12:24:11 UTC


README

此包为Simshauns php Recurr package添加了Eloquent辅助工具。

Latest Version on Packagist Total Downloads

安装

您可以通过composer安装此包

composer require tanthammar/recurring

重要

  • start_atend_at应存储在其时区中,而不是在数据库中转换为utc。Builder将使用时区属性进行转换。
  • end_at代表持续时间而非最后一次出现,来源:simshaun/recurr#44

用法

假设您在代码库中有一个DatePattern模型。

Builder会结合时区属性解析它们。

您的模型必须具有以下属性

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

IsRecurring特质应用到模型上

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

将字符串rrule保存到str_rule字段后,您将能够访问以下方法。有关其他方法的更多信息,请参阅https://github.com/simshaun/recurr

所有RecurrenceCollection方法返回的最大重复次数为732次。(与父包simshaun/recurr相同)。使用$count参数设置您想要返回的重复次数。

$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

贡献

欢迎所有贡献,提交PR吧:)

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件