-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoordinationId.php
62 lines (51 loc) · 2.05 KB
/
CoordinationId.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace byrokrat\id;
use byrokrat\id\Helper\DateTimeCreator;
use byrokrat\id\Helper\NumberParser;
use byrokrat\id\Exception\UnableToCreateIdException;
class CoordinationId extends PersonalId
{
/**
* @var string
*/
private $datestr;
/**
* Create coordination id number
*
* A coordination number is like a personal number except that 60 is added
* to the date of birth.
*
* NOTE that coordination numbers may contain a date that does not actually
* exist. The month and day parts may on some cases be set to '00'. And
* the day part may in some cases refer to undefined dates, such as the 30th
* of february. In these cases the parser will convert the date to a valid
* date, even though it may not reflect the actual birth date.
*
* @param string $raw The raw id to parse
* @param \DateTimeInterface $atDate Optional date when parsing takes place, defaults to today
* @throws UnableToCreateIdException On failure to create id
*/
public function __construct(string $raw, \DateTimeInterface $atDate = null)
{
list($century, $this->datestr, $delim, $serialPost, $check) = NumberParser::parse(self::PATTERN, $raw);
// remove 60 and preserve left side zeros
$compensatedDatestr = str_pad((string)(intval($this->datestr) - 60), 6, '0', STR_PAD_LEFT);
$compensatedFormat = 'ymd';
if ($century) {
$compensatedDatestr = $century . $compensatedDatestr;
$compensatedFormat = 'Ymd';
}
// parse a date of birth even though datestr may refer a date that does not actually exist
$dateOfBirth = DateTimeCreator::createFromFormat($compensatedFormat, $compensatedDatestr);
parent::__construct($century . $dateOfBirth->format('ymd') . $delim . $serialPost . $check, $atDate);
}
public function getSerialPreDelimiter(): string
{
return $this->datestr;
}
public function getBirthCounty(): string
{
return Counties::COUNTY_UNDEFINED;
}
}