 
 
 
 
 
 
 
 , (*1)
, (*1)
SmartSleep
Installation
Pretty simple with Composer, run:, (*2)
composer require anime-db/smart-sleep
How-to
First build schedule, (*3)
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)
]);
Configure SmartSleep, (*4)
use AnimeDb\SmartSleep\SmartSleep;
$smart = new SmartSleep($schedule);
And now we can sleep, (*5)
$seconds = $smart->sleepForSeconds(new \DateTimeImmutable());
sleep($seconds);
Rules
SpecificDayRule
The rule corresponds to specific day in the specified time interval.
Can be used for public holidays., (*6)
$rule = new SpecificDayRule(new \DateTimeImmutable('2017-01-01'), $start_hour, $end_hour, $max_sleep_seconds)
EverydayRule
The rule corresponds to any day in the specified time interval., (*7)
$rule = new EverydayRule($start_hour, $end_hour, $max_sleep_seconds)
HolidayRule
The rule corresponds to the holiday at the specified time interval., (*8)
$rule = new HolidayRule($start_hour, $end_hour, $max_sleep_seconds)
WeekdayRule
The rule corresponds to the weekday at the specified time interval., (*9)
$rule = new WeekdayRule($start_hour, $end_hour, $max_sleep_seconds)
OnceDayRule
The rule always corresponds to the specified time.
Returns the seconds in the next day., (*10)
$rule = new OnceDayRule()
OnceWeekRule
The rule always corresponds to the specified time.
Returns the seconds in the next week., (*11)
$rule = new OnceWeekRule()
OnceMonthRule
The rule always corresponds to the specified time.
Returns the seconds in the next month., (*12)
$rule = new OnceMonthRule()
License
This bundle is under the MIT license. See the complete license in the file: LICENSE, (*13)