Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Latvian personal identity method #472

Merged
merged 2 commits into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,17 @@ echo $faker->firstKanaName; // "ハルカ"
echo $faker->lastKanaName; // "ナカジマ"
```


### `Faker\Provider\lv_LV\Person`

```php
<?php

// Generates a random personal identity card number
echo $faker->personalIdentityNumber; // "140190-12301"

```

### `Faker\Provider\pl_PL\Person`

```php
Expand Down
22 changes: 22 additions & 0 deletions src/Faker/Provider/lv_LV/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Faker\Provider\lv_LV;

use Faker\Calculator\Luhn;

class Person extends \Faker\Provider\Person
{
/**
Expand Down Expand Up @@ -58,4 +60,24 @@ public function passportNumber()
{
return $this->bothify("??#######");
}

/**
* National Personal Identity number (personas kods)
* @link https://en.wikipedia.org/wiki/National_identification_number#Latvia
* @param \DateTime $birthdate
* @return string on format XXXXXX-XXXXX
*/
public function personalIdentityNumber(\DateTime $birthdate = null)
{
if (!$birthdate) {
$birthdate = \Faker\Provider\DateTime::dateTimeThisCentury();
}

$datePart = $birthdate->format('dmy');
$randomDigits = (string) static::numerify('####');

$checksum = Luhn::computeCheckDigit($datePart . $randomDigits);

return $datePart . '-' . $randomDigits . $checksum;
}
}