1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace byrokrat\id; |
6
|
|
|
|
7
|
|
|
use byrokrat\id\Helper\DateTimeCreator; |
8
|
|
|
use byrokrat\id\Helper\NumberParser; |
9
|
|
|
use byrokrat\id\Exception\UnableToCreateIdException; |
10
|
|
|
|
11
|
|
|
class CoordinationId extends PersonalId |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $datestr; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Create coordination id number |
20
|
46 |
|
* |
21
|
|
|
* A coordination number is like a personal number except that 60 is added |
22
|
46 |
|
* to the date of birth. |
23
|
28 |
|
* |
24
|
28 |
|
* NOTE that coordination numbers may contain a date that does not actually |
25
|
10 |
|
* exist. The month and day parts may on some cases be set to '00'. And |
26
|
|
|
* the day part may in some cases refer to undefined dates, such as the 30th |
27
|
28 |
|
* of february. In these cases the parser will convert the date to a valid |
28
|
|
|
* date, even though it may not reflect the actual birth date. |
29
|
28 |
|
* |
30
|
|
|
* @param string $raw The raw id to parse |
31
|
|
|
* @param \DateTimeInterface $atDate Optional date when parsing takes place, defaults to today |
32
|
1 |
|
* @throws UnableToCreateIdException On failure to create id |
33
|
|
|
*/ |
34
|
1 |
|
public function __construct(string $raw, \DateTimeInterface $atDate = null) |
35
|
|
|
{ |
36
|
|
|
list($century, $this->datestr, $delim, $serialPost, $check) = NumberParser::parse(self::PATTERN, $raw); |
37
|
|
|
|
38
|
|
|
// remove 60 and preserve left side zeros |
39
|
|
|
$compensatedDatestr = str_pad((string)(intval($this->datestr) - 60), 6, '0', STR_PAD_LEFT); |
40
|
|
|
$compensatedFormat = 'ymd'; |
41
|
|
|
|
42
|
|
|
if ($century) { |
43
|
|
|
$compensatedDatestr = $century . $compensatedDatestr; |
44
|
|
|
$compensatedFormat = 'Ymd'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// parse a date of birth even though datestr may refer a date that does not actually exist |
48
|
|
|
$dateOfBirth = DateTimeCreator::createFromFormat($compensatedFormat, $compensatedDatestr); |
49
|
|
|
|
50
|
|
|
parent::__construct($century . $dateOfBirth->format('ymd') . $delim . $serialPost . $check, $atDate); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getSerialPreDelimiter(): string |
54
|
|
|
{ |
55
|
|
|
return $this->datestr; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getBirthCounty(): string |
59
|
|
|
{ |
60
|
|
|
return Counties::COUNTY_UNDEFINED; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|