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

Add nik to indonesia #1019

Merged
merged 3 commits into from
Sep 9, 2016
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
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,18 @@ echo $faker->siret; // 347 355 708 00224
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;
}
}