Statistics
451
2
0
63d
Badges
Tags
utils
Dependencies

Czech birth number value object

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/birth-number

Usage

Creating value object

The parser is quite benevolent with regard to the delimiter separating the ending of birth number.

$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('0421010030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 / 0030');

Nepada\BirthNumber\InvalidBirthNumberException is thrown in case of invalid input value.

Converting back to string

echo((string) $birthNumber); // '042101/0030'
echo($birthNumber->toString()); // '042101/0030'
echo($birthNumber->toStringWithoutSlash()); // '0421010030'

Validation

Nepada\BirthNumber\BirthNumber::isValid('0421010030'); // true
Nepada\BirthNumber\BirthNumber::isValid('9999999999'); // false

Comparison

$birthNumber1 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber2 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber1->equals($birthNumber2); // true

Extracting information from birth number

$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('047101 / 0090');
$birthNumber->getBirthDate(); // \DateTimeImmutable('2004-01-01')

$gender = $birthNumber->getGender(); // Nepada\BirthNumber\Gender enum instance
$gender->isFemale(); // true
$gender->isMale(); // false
$gender->toString(); // 'female'

Integrations

  • v1.0.0 1.0.0

    • Initial release.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com