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 #1019 from Nuffic/add_nik_to_indonesia
Browse files Browse the repository at this point in the history
Add nik to indonesia
  • Loading branch information
fzaninotto authored Sep 9, 2016
2 parents 5ec9225 + 793d5a3 commit e912cd6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ echo $faker->bankAccountNumber // "HR3789114847226078672"
echo $faker->bankAccountNumber; // "HU09904437680048220079300783"
```

### `Faker\Provider\id_ID\Person`

```php
<?php

// Generates a random Nomor Induk Kependudukan (NIK)

// first argument is gender, either Person::GENDER_MALE or Person::GENDER_FEMALE, if none specified random gender is used
// second argument is birth date (DateTime object), if none specified, random birth date is used
echo $faker->nik(); // "8522246001570940"
```

### `Faker\Provider\it_IT\Company`

```php
Expand Down
37 changes: 37 additions & 0 deletions src/Faker/Provider/id_ID/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,41 @@ public static function suffix()
{
return static::randomElement(static::$suffix);
}

/**
* Generates Nomor Induk Kependudukan (NIK)
*
* @link https://en.wikipedia.org/wiki/National_identification_number#Indonesia
*
* @param null|string $gender
* @param null|\DateTime $birthDate
* @return string
*/
public function nik($gender = null, $birthDate = null)
{
# generate first numbers (region data)
$nik = $this->generator->numerify('######');

if (!$birthDate) {
$birthDate = $this->generator->dateTimeBetween();
}

if (!$gender) {
$gender = $this->generator->randomElement(array(self::GENDER_MALE, self::GENDER_FEMALE));
}

# if gender is female, add 40 to days
if ($gender == self::GENDER_FEMALE) {
$nik .= $birthDate->format('d') + 40;
} else {
$nik .= $birthDate->format('d');
}

$nik .= $birthDate->format('my');

# add last random digits
$nik.= $this->generator->numerify('####');

return $nik;
}
}

0 comments on commit e912cd6

Please sign in to comment.