PHP code example of anime-db / smart-sleep

1. Go to this page and download the library: Download anime-db/smart-sleep library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anime-db / smart-sleep example snippets


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

use AnimeDb\SmartSleep\SmartSleep;

$smart = new SmartSleep($schedule);

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

sleep($seconds);

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

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

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

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

$rule = new OnceDayRule()

$rule = new OnceWeekRule()

$rule = new OnceMonthRule()