https://github.com/anime-db/smart-sleep
SmartSleep util
https://github.com/anime-db/smart-sleep
component php
Last synced: 2 months ago
JSON representation
SmartSleep util
- Host: GitHub
- URL: https://github.com/anime-db/smart-sleep
- Owner: anime-db
- License: mit
- Created: 2016-06-22T13:02:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-25T13:06:46.000Z (almost 8 years ago)
- Last Synced: 2025-02-14T21:54:58.655Z (4 months ago)
- Topics: component, php
- Language: PHP
- Size: 90.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/anime-db/smart-sleep)
[](https://packagist.org/packages/anime-db/smart-sleep)
[](https://travis-ci.org/anime-db/smart-sleep)
[](https://coveralls.io/github/anime-db/smart-sleep?branch=master)
[](https://scrutinizer-ci.com/g/anime-db/smart-sleep/?branch=master)
[](https://insight.sensiolabs.com/projects/22dbc4bf-167a-468b-b84e-014f4a8d23ff)
[](https://styleci.io/repos/61719557)
[](https://github.com/anime-db/smart-sleep)SmartSleep
==========Installation
------------Pretty simple with [Composer](http://packagist.org), run:
```sh
composer require anime-db/smart-sleep
```How-to
------First build schedule
```php
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
```php
use AnimeDb\SmartSleep\SmartSleep;$smart = new SmartSleep($schedule);
```And now we can sleep
```php
$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.```php
$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.
```php
$rule = new EverydayRule($start_hour, $end_hour, $max_sleep_seconds)
```### HolidayRule
The rule corresponds to the holiday at the specified time interval.
```php
$rule = new HolidayRule($start_hour, $end_hour, $max_sleep_seconds)
```### WeekdayRule
The rule corresponds to the weekday at the specified time interval.
```php
$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.```php
$rule = new OnceDayRule()
```### OnceWeekRule
The rule always corresponds to the specified time.
Returns the seconds in the next week.```php
$rule = new OnceWeekRule()
```### OnceMonthRule
The rule always corresponds to the specified time.
Returns the seconds in the next month.```php
$rule = new OnceMonthRule()
```License
-------This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE