PHPackages                             anime-db/smart-sleep - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. anime-db/smart-sleep

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

anime-db/smart-sleep
====================

Smart sleep

v2.1.0(8y ago)029MITPHPPHP &gt;=5.4.0

Since Jun 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/anime-db/smart-sleep)[ Packagist](https://packagist.org/packages/anime-db/smart-sleep)[ Docs](http://github.com/anime-db/smart-sleep)[ RSS](/packages/anime-db-smart-sleep/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (3)Versions (7)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5251d396670f838b62b8483491f741ed1cc4ea2abe7144d7f0b0e0f098bacf30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/anime-db/smart-sleep)[![Total Downloads](https://camo.githubusercontent.com/2a66574f95f14401124b287fd65ce58aa4158ca4592b06142f41a9f06f696b47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030)](https://packagist.org/packages/anime-db/smart-sleep)[![Build Status](https://camo.githubusercontent.com/c7317d16c11482a65ace2c0602c66767b96bc589f9766bd941aaec55bbaab7d7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030)](https://travis-ci.org/anime-db/smart-sleep)[![Coverage Status](https://camo.githubusercontent.com/6a00205c307f2a265e200a439e34ff48c5e555e1f8c480ee2c355d0a1a8bc31c/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030)](https://coveralls.io/github/anime-db/smart-sleep?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e6b91eefdc6706bf73e1cf9e499d1806b6fa942cd84bc7d4438ff1133523254f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/anime-db/smart-sleep/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/5155ed5db150b787555795466aae029dc9bc425cc289cfd9ca1c99a333cf18a9/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f32326462633462662d313637612d343638622d623834652d3031346634613864323366662e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/22dbc4bf-167a-468b-b84e-014f4a8d23ff)[![StyleCI](https://camo.githubusercontent.com/c7e9e07f43517544fffdff9ee5a66b3400133b6ac10ee7aa8846dbd796c734dc/68747470733a2f2f7374796c6563692e696f2f7265706f732f36313731393535372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/61719557)[![License](https://camo.githubusercontent.com/c4b3b48817987462e102020e941a657efec36d8578306860dfdaeb46bbe72c0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e696d652d64622f736d6172742d736c6565702e7376673f6d61784167653d33363030)](https://github.com/anime-db/smart-sleep)

SmartSleep
==========

[](#smartsleep)

Installation
------------

[](#installation)

Pretty simple with [Composer](http://packagist.org), run:

```
composer require anime-db/smart-sleep
```

How-to
------

[](#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
-----

[](#rules)

### SpecificDayRule

[](#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

[](#everydayrule)

The rule corresponds to any day in the specified time interval.

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

### HolidayRule

[](#holidayrule)

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

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

### WeekdayRule

[](#weekdayrule)

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

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

### OnceDayRule

[](#oncedayrule)

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

```
$rule = new OnceDayRule()
```

### OnceWeekRule

[](#onceweekrule)

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

```
$rule = new OnceWeekRule()
```

### OnceMonthRule

[](#oncemonthrule)

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

```
$rule = new OnceMonthRule()
```

License
-------

[](#license)

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~95 days

Total

6

Last Release

3262d ago

Major Versions

v1.0.2 → v2.0.02017-07-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (110 commits)")

---

Tags

componentphpphpsleep

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anime-db-smart-sleep/health.svg)

```
[![Health](https://phpackages.com/badges/anime-db-smart-sleep/health.svg)](https://phpackages.com/packages/anime-db-smart-sleep)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21422.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
