View Source Nip.Pns (indonesian_id v1.1.0)

Functions for working with NIP PNS (Nomor Induk Pegawai Negeri Sipil)

NIP PNS consists of 18 digits divided into 4 parts:

  • 8 digits for birth date (YYYYMMDD)
  • 6 digits for TMT (Tanggal Mulai Tugas) (YYYYMM)
  • 1 digit for sex code (1 for male and 2 for female)
  • 3 digits for serial number (001-999)

Summary

Functions

Parse NIP PNS into a struct.

Validate NIP format.

Types

nip_result()

@type nip_result() :: {:ok, t()} | {:error, String.t()}

t()

@type t() :: %Nip.Pns{
  birth_date: Date.t(),
  nip: String.t(),
  serial_number: String.t(),
  sex: String.t(),
  tmt_date: Date.t()
}

validated_nip_result()

@type validated_nip_result() :: {:ok, String.t()} | {:error, String.t()}

Functions

parse(nip)

@spec parse(String.t()) :: nip_result()

Parse NIP PNS into a struct.

Returns {:ok, %Nip.Pns{}} if the NIP is valid, otherwise {:error, reason}.

Examples

iex> Nip.Pns.parse("200012312024121001")
{:ok,
%Nip.Pns{
  nip: "200012312024121001",
  birth_date: ~D[2000-12-31],
  tmt_date: ~D[2024-12-01],
  sex: "M",
  serial_number: "001"
}}

validate_format(nip)

@spec validate_format(String.t()) :: validated_nip_result()

Validate NIP format.

Returns {:ok, nip} if the NIP is valid, otherwise {:error, reason}.

Examples

iex> Nip.Pns.validate_format("200012312024121001")
{:ok, "200012312024121001"}