-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path004.php
46 lines (34 loc) · 1.3 KB
/
004.php
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
<?php
class Draw {
/**
* @var DateTime
*/
private $relativeDate;
public function nextValidDrawDate(DateTime $relativeDate = null)
{
$this->relativeDate = $relativeDate ?: new DateTime();
$relativeDate1 = clone $this->relativeDate;
$relativeDate2 = clone $this->relativeDate;
$relativeDate1->modify('next Monday');
$relativeDate2->modify('next Thursday');
$day = $this->relativeDate->format('D');
$hours = $this->relativeDate->format('H');
$minutes = $this->relativeDate->format('i');
//When today is still a valid draw date
if(in_array($day, ['Mon', 'Thu']) && $hours < 21 && $minutes < 30){
return $this->relativeDate->format('Y-m-d');
}
//When Monday is closer to the relative date
if($relativeDate1 < $relativeDate2){
return $relativeDate1->format('Y-m-d');
}else{
//When next Thursday is closer to the relative date
return $relativeDate2->format('Y-m-d');
}
}
}
$drawInstance = new Draw();
$result = $drawInstance->nextValidDrawDate(new DateTime('2019-04-29 10:00'));
echo $result.PHP_EOL;//2019-04-29
$result = $drawInstance->nextValidDrawDate(new DateTime('2019-04-30 10:00'));
echo $result.PHP_EOL;//2019-05-02