smhg/date-frequency

时间频率库

v4.0.2 2024-03-11 12:49 UTC

README

时间频率库

PHP 版本,基于 JavaScript 版本.

安装

$ composer require smhg/date-frequency

方法

频率

use Frequency\Frequency;

$frequency = new Frequency();
$frequency->on('day', 3, 'week')
	->on('hour', 10)
	->on('minute', 0)
	->on('seconds', 0); // every Wednesday at 10:00:00

Frequency([string rules])

Frequency([array rules])

将规则作为字符串(参见 __toString)或数组传递给构造函数,而不是使用 on() 逐个设置。

上面的示例作为字符串:$frequency = new Frequency('F3D/WT10H0M0S');

on(string unit, int|string value, [string scope])

向频率添加一个规则(固定整数值或表示过滤器函数名称的字符串),对于单位,可选地链接到作用域(如果没有提供,将推导出一个默认作用域)。

当使用时,过滤器函数需要在静态 Frequency::$fn 数组中可用。

示例过滤器:$frequency = new Frequency('F(leap)Y1M1DT0H0M0S');(闰年的1月1日午夜)

查看测试以获取更多示例。

next(DateTime start = new DateTime())

获取在或之后某个日期的频率的下一次出现。

between(DateTime start, DateTime end)

获取两个日期之间所有频率的出现。

__toString()

将频率转换为字符串值。