anime-db/smart-sleep

v2.1.0 2017-07-25 13:02 UTC

This package is auto-updated.

Last update: 2024-09-15 19:37:35 UTC


README

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License

SmartSleep

安装

使用 Composer 非常简单,运行

composer require anime-db/smart-sleep

如何操作

首次构建计划

use AnimeDb\SmartSleep\Rule\EverydayRule;
use AnimeDb\SmartSleep\Schedule;

$schedule = new Schedule([
    new EverydayRule(0, 3, 260), // [00:00, 03:00)
    new EverydayRule(3, 9, 900), // [03:00, 09:00)
    new EverydayRule(9, 19, 160), // [09:00, 19:00)
    new EverydayRule(19, 23, 70), // [19:00, 23:00)
    new EverydayRule(23, 24, 60), // [23:00, 24:00)
]);

配置 SmartSleep

use AnimeDb\SmartSleep\SmartSleep;

$smart = new SmartSleep($schedule);

现在我们可以去睡觉了

$seconds = $smart->sleepForSeconds(new \DateTimeImmutable());

sleep($seconds);

规则

SpecificDayRule

该规则对应于指定时间间隔内的特定日期。可用于公共假日。

$rule = new SpecificDayRule(new \DateTimeImmutable('2017-01-01'), $start_hour, $end_hour, $max_sleep_seconds)

EverydayRule

该规则对应于指定时间间隔内的任何一天。

$rule = new EverydayRule($start_hour, $end_hour, $max_sleep_seconds)

HolidayRule

该规则对应于指定时间间隔内的假日。

$rule = new HolidayRule($start_hour, $end_hour, $max_sleep_seconds)

WeekdayRule

该规则对应于指定时间间隔内的工作日。

$rule = new WeekdayRule($start_hour, $end_hour, $max_sleep_seconds)

OnceDayRule

该规则始终对应于指定的时间。返回下一天的时间戳。

$rule = new OnceDayRule()

OnceWeekRule

该规则始终对应于指定的时间。返回下周的时间戳。

$rule = new OnceWeekRule()

OnceMonthRule

该规则始终对应于指定的时间。返回下月的时间戳。

$rule = new OnceMonthRule()

许可证

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