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