| @@ 10-45 (lines=36) @@ | ||
| 7 | */ |
|
| 8 | namespace AnimeDb\SmartSleep\Rule; |
|
| 9 | ||
| 10 | class OnceDayRule extends RuleBase |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var \DateTime |
|
| 14 | */ |
|
| 15 | protected $time; |
|
| 16 | ||
| 17 | public function __construct() |
|
| 18 | { |
|
| 19 | $this->time = new \DateTime(); // default time |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param \DateTime $time |
|
| 24 | * |
|
| 25 | * @return bool |
|
| 26 | */ |
|
| 27 | public function isMatched(\DateTime $time) |
|
| 28 | { |
|
| 29 | $this->time = clone $time; // save current time |
|
| 30 | ||
| 31 | return true; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return int |
|
| 36 | */ |
|
| 37 | public function getSeconds() |
|
| 38 | { |
|
| 39 | $offset_time = clone $this->time; |
|
| 40 | $offset_time->modify('+1 day 00:00:00'); |
|
| 41 | $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next day |
|
| 42 | ||
| 43 | return $offset + rand(0, 86400); // 86400 is a 1 day |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| @@ 10-45 (lines=36) @@ | ||
| 7 | */ |
|
| 8 | namespace AnimeDb\SmartSleep\Rule; |
|
| 9 | ||
| 10 | class OnceWeekRule extends RuleBase |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var \DateTime |
|
| 14 | */ |
|
| 15 | protected $time; |
|
| 16 | ||
| 17 | public function __construct() |
|
| 18 | { |
|
| 19 | $this->time = new \DateTime(); // default time |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param \DateTime $time |
|
| 24 | * |
|
| 25 | * @return bool |
|
| 26 | */ |
|
| 27 | public function isMatched(\DateTime $time) |
|
| 28 | { |
|
| 29 | $this->time = clone $time; // save current time |
|
| 30 | ||
| 31 | return true; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return int |
|
| 36 | */ |
|
| 37 | public function getSeconds() |
|
| 38 | { |
|
| 39 | $offset_time = clone $this->time; |
|
| 40 | $offset_time->modify('+1 week 00:00:00'); |
|
| 41 | $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next week |
|
| 42 | ||
| 43 | return $offset + rand(0, 604800); // 604800 is a 1 week |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||