| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Promotions\Domain; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Time_Interval |
| 7 |
* |
| 8 |
* Value object for a time interval. |
| 9 |
*/ |
| 10 |
class Time_Interval { |
| 11 |
|
| 12 |
/** |
| 13 |
* The starting time of the interval as a Unix timestamp. |
| 14 |
* |
| 15 |
* @var int |
| 16 |
*/ |
| 17 |
public $time_start; |
| 18 |
|
| 19 |
/** |
| 20 |
* The ending time of the interval as a Unix timestamp. |
| 21 |
* |
| 22 |
* @var int |
| 23 |
*/ |
| 24 |
public $time_end; |
| 25 |
|
| 26 |
/** |
| 27 |
* Time_Interval constructor. |
| 28 |
* |
| 29 |
* @codeCoverageIgnore |
| 30 |
* |
| 31 |
* @param int $time_start Interval start time. |
| 32 |
* @param int $time_end Interval end time. |
| 33 |
*/ |
| 34 |
public function __construct( int $time_start, int $time_end ) { |
| 35 |
$this->time_start = $time_start; |
| 36 |
$this->time_end = $time_end; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Checks if the given time is within the interval. |
| 41 |
* |
| 42 |
* @param int $time The time to check. |
| 43 |
* |
| 44 |
* @return bool Whether the given time is within the interval. |
| 45 |
*/ |
| 46 |
public function contains( int $time ): bool { |
| 47 |
return ( ( $time > $this->time_start ) && ( $time < $this->time_end ) ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Sets the interval astarting date. |
| 52 |
* |
| 53 |
* @param int $time_start The interval start time. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function set_start_date( int $time_start ) { |
| 58 |
$this->time_start = $time_start; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Sets the interval ending date. |
| 63 |
* |
| 64 |
* @param int $time_end The interval end time. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function set_end_date( int $time_end ) { |
| 69 |
$this->time_end = $time_end; |
| 70 |
} |
| 71 |
} |
| 72 |
|