ecommit/frequency-generator

根据频率获取下一个日期。

v2.0.2 2022-05-05 10:55 UTC

This package is auto-updated.

Last update: 2024-08-30 14:28:11 UTC


README

根据频率获取下一个日期(DateTime对象)。

Tests

安装

要使用Composer安装frequency-generator,只需运行

$ composer require ecommit/frequency-generator

使用方法

创建生成器

use Ecommit\FrequencyGenerator\FrequencyGenerator;

$generator = new FrequencyGenerator();

频率 "每天"

//Every day at 08:00:00 and 10:00:00
$dateTimeObject = $generator->nextInEveryDay([new \DateTime('10:00:00'), new \DateTime('08:00:00')]);

参数

  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

频率 "每周"

//Every monday (at 08:00:00 and 10:00:00) and tuesday (at 08:00:00 and 10:00:00)
$dateTimeObject = $generator->nextInEveryWeek([1, 2], [new \DateTime('10:00:00'), new \DateTime('08:00:00')]);

参数

  • array $days 周中天数的数组(整数)。(1=周一 => 7=周日)。默认:仅 1(周一)
  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

频率 "每月"

//Every 1st (at 08:00:00 and 10:00:00) and 2nd (at 08:00:00 and 10:00:00)
$dateTimeObject = $generator->nextInEveryMonth([1, 2], [new \DateTime('10:00:00'), new \DateTime('08:00:00')]);

参数

  • array $days 月份中天数的数组(整数)。(1=>31)。默认:仅 1(1日)
  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

频率 "每季度"

//Every 1st and 15th February, May, August and November (at 08:00:00 and 10:00:00)  
$dateTimeObject = $generator->nextInEveryQuart([2], [1, 15], [new \DateTime('10:00:00'), new \DateTime('08:00:00')]);

参数

  • array $monthOffsets 季度中月份偏移量的数组(整数)。1 = 一月,四月,七月,十月。2 = 二月,五月,八月,十一月。3 = 三月,六月,九月,十二月)。默认:仅 1(一月,四月,七月,十月)
  • array $daysInMonth 月份中天数的数组(整数)。(1=>31)。默认:仅 1(1日)
  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

频率 "每半年"

//Every 1st and 15th February and August (at 08:00:00 and 10:00:00)  
$dateTimeObject = $generator->nextInEveryHalfYear([2], [1, 15], [new \DateTime('10:00:00'), new \DateTime('08:00:00')]);
  • array $monthOffsets 半年中月份偏移量的数组(整数)。1 = 一月,七月。2 = 二月,八月。3 = 三月,九月。4 = 四月,十月。5 = 五月,十一月。6 = 六月,十二月)。默认:仅 1(一月,七月)
  • array $daysInMonth 月份中天数的数组(整数)。(1=>31)。默认:仅 1(1日)
  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

频率 "每年"

//Every 1st and 15th January (at 08:00:00 and 10:00:00)  
$dateTimeObject = $generator->nextInEveryYear([1], [1, 15], [new \DateTime('10:00:00'), new \DateTime('08:00:00')]);
  • array $monthOffsets 年中月份偏移量的数组(整数)。1 = 一月 => 12 => 十二月)。默认:仅 1(一月)
  • array $daysInMonth 月份中天数的数组(整数)。(1=>31)。默认:仅 1(1日)
  • array $times 时间(DateTime或DateTimeImmutable对象的数组)。默认:仅 00:00:00

生成DateTimeImmutable对象

生成器默认生成DateTime对象。

生成器可以通过generateDateTimeImmutable方法生成DateTimeImmutable对象。

use Ecommit\FrequencyGenerator\FrequencyGenerator;

$generator = new FrequencyGenerator();

$date = $generator->nextInEveryDay([new \DateTime('10:00:00'), new \DateTime('08:00:00')]);
echo get_class($date); //This example will output "DateTime"

$generator->generateDateTimeImmutable(true);
$date = $generator->nextInEveryDay([new \DateTime('10:00:00'), new \DateTime('08:00:00')]);
echo get_class($date); //This example will output "DateTimeImmutable"

$generator->generateDateTimeImmutable(false);
$date = $generator->nextInEveryDay([new \DateTime('10:00:00'), new \DateTime('08:00:00')]);
echo get_class($date); //This example will output "DateTime"

许可证

此库采用MIT许可证。请参阅LICENSE文件中的完整许可证。