-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDayOfMonth.php
More file actions
39 lines (31 loc) · 1.06 KB
/
DayOfMonth.php
File metadata and controls
39 lines (31 loc) · 1.06 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
<?php
namespace MatchBot\Domain;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use MatchBot\Application\Assertion;
/**
* A day number for a monthly event, between 1 and 28.
* For simplicity of being able to have the same day every month we do not allow day numbers 29,30 or 31.
*/
#[Embeddable]
readonly class DayOfMonth
{
private function __construct(
#[Column(name: "dayOfMonth", type: 'smallint')]
public int $value
) {
Assertion::between($value, 1, 28);
}
public static function of(int $day): DayOfMonth
{
return new self($day);
}
public static function forMandateStartingAt(\DateTimeImmutable $date): self
{
$dateInUK = $date->setTimezone(new \DateTimeZone('Europe/London'));
$originalDayOfMonth = (int)$dateInUK->format('j');
// for simplicity, we don't take payments on the 29th, 30th or 31st of the month since not all months have them.
$constrainedDayOfMOnth = min(28, $originalDayOfMonth);
return self::of($constrainedDayOfMOnth);
}
}