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

Commit

Permalink
Merge pull request #472 from MatissJA/master
Browse files Browse the repository at this point in the history
Latvian personal identity method
  • Loading branch information
fzaninotto committed Jan 22, 2015
2 parents e64f1ed + 9a301ea commit b1167d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,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;
}
}

0 comments on commit b1167d9

Please sign in to comment.