@@ 11-37 (lines=27) @@ | ||
8 | ||
9 | namespace AnimeDb\SmartSleep\Rule; |
|
10 | ||
11 | class EverydayRule implements HourIntervalRule |
|
12 | { |
|
13 | use HourlyIntervalRuleTrait; |
|
14 | use RandSecondsRuleTrait; |
|
15 | ||
16 | /** |
|
17 | * @param int $start |
|
18 | * @param int $end |
|
19 | * @param int $seconds |
|
20 | */ |
|
21 | public function __construct($start, $end, $seconds) |
|
22 | { |
|
23 | $this->setStart($start); |
|
24 | $this->setEnd($end); |
|
25 | $this->setSeconds($seconds); |
|
26 | } |
|
27 | ||
28 | /** |
|
29 | * @param \DateTime $time |
|
30 | * |
|
31 | * @return bool |
|
32 | */ |
|
33 | public function isMatched(\DateTime $time) |
|
34 | { |
|
35 | return $this->start() <= $time->format('G') && $this->end() > $time->format('G'); |
|
36 | } |
|
37 | } |
|
38 |
@@ 11-41 (lines=31) @@ | ||
8 | ||
9 | namespace AnimeDb\SmartSleep\Rule; |
|
10 | ||
11 | class HolidayRule implements HourIntervalRule |
|
12 | { |
|
13 | use HourlyIntervalRuleTrait; |
|
14 | use RandSecondsRuleTrait; |
|
15 | ||
16 | /** |
|
17 | * @param int $start |
|
18 | * @param int $end |
|
19 | * @param int $seconds |
|
20 | */ |
|
21 | public function __construct($start, $end, $seconds) |
|
22 | { |
|
23 | $this->setStart($start); |
|
24 | $this->setEnd($end); |
|
25 | $this->setSeconds($seconds); |
|
26 | } |
|
27 | ||
28 | /** |
|
29 | * @param \DateTime $time |
|
30 | * |
|
31 | * @return bool |
|
32 | */ |
|
33 | public function isMatched(\DateTime $time) |
|
34 | { |
|
35 | return |
|
36 | $time->format('N') > 5 && |
|
37 | $this->start() <= $time->format('G') && |
|
38 | $this->end() > $time->format('G') |
|
39 | ; |
|
40 | } |
|
41 | } |
|
42 |
@@ 11-41 (lines=31) @@ | ||
8 | ||
9 | namespace AnimeDb\SmartSleep\Rule; |
|
10 | ||
11 | class WeekdayRule implements HourIntervalRule |
|
12 | { |
|
13 | use HourlyIntervalRuleTrait; |
|
14 | use RandSecondsRuleTrait; |
|
15 | ||
16 | /** |
|
17 | * @param int $start |
|
18 | * @param int $end |
|
19 | * @param int $seconds |
|
20 | */ |
|
21 | public function __construct($start, $end, $seconds) |
|
22 | { |
|
23 | $this->setStart($start); |
|
24 | $this->setEnd($end); |
|
25 | $this->setSeconds($seconds); |
|
26 | } |
|
27 | ||
28 | /** |
|
29 | * @param \DateTime $time |
|
30 | * |
|
31 | * @return bool |
|
32 | */ |
|
33 | public function isMatched(\DateTime $time) |
|
34 | { |
|
35 | return |
|
36 | $time->format('N') <= 5 && |
|
37 | $this->start() <= $time->format('G') && |
|
38 | $this->end() > $time->format('G') |
|
39 | ; |
|
40 | } |
|
41 | } |
|
42 |