anime-db/smart-sleep

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

This package is auto-updated.

Last update: 2024-04-15 18:47:55 UTC


README

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

SmartSleep

Installation

Pretty simple with Composer, run:

composer require anime-db/smart-sleep

How-to

First build schedule

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

use AnimeDb\SmartSleep\SmartSleep;

$smart = new SmartSleep($schedule);

And now we can sleep

$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.

$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.

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

HolidayRule

The rule corresponds to the holiday at the specified time interval.

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

WeekdayRule

The rule corresponds to the weekday at the specified time interval.

$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.

$rule = new OnceDayRule()

OnceWeekRule

The rule always corresponds to the specified time. Returns the seconds in the next week.

$rule = new OnceWeekRule()

OnceMonthRule

The rule always corresponds to the specified time. Returns the seconds in the next month.

$rule = new OnceMonthRule()

License

This bundle is under the MIT license. See the complete license in the file: LICENSE