pin

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package pin provides parsing and validation for German Pension Insurance Numbers (Rentenversicherungsnummer).

Index

Constants

View Source
const (
	// 0
	// 1
	AreaMecklenburgWesternPomerania = 2
	AreaThuringia                   = 3
	AreaBrandenburg                 = 4
	// 5
	// 6
	// 7
	AreaSaxonyAnhalt                = 8
	AreaSaxony                      = 9
	AreaHanover                     = 10
	AreaWestphalia                  = 11
	AreaHesse                       = 12
	AreaRhineProvince               = 13
	AreaUpperBavaria                = 14
	AreaLowerBavariaUpperPalatinate = 15
	AreaRhinelandPalatinate         = 16
	AreaSaarland                    = 17
	AreaUpperAndMiddleFranconia     = 18
	AreaHamburg                     = 19
	AreaLowerFranconia              = 20
	AreaSwabia                      = 21
	// 22
	AreaWurttemberg       = 23
	AreaBaden             = 24
	AreaBerlin            = 25
	AreaSchleswigHolstein = 26
	// 27
	AreaOldenburgBremen = 28
	AreaBraunschweig    = 29
	// 30
	// 31
	// 32
	// 33
	// 34
	// 35
	// 36
	// 37
	AreaKnappschaftBahnSee_Bahn          = 38
	AreaKnappschaftBahnSee_See           = 39
	AreaZulagenstelleFuerAltersvermoegen = 40

	// 41
	AreaBundMecklenburgWesternPomerania = 2 + 40
	AreaBundThuringia                   = 3 + 40
	AreaBundBrandenburg                 = 4 + 40
	// 45
	// 46
	// 47
	AreaBundSaxonyAnhalt                = 8 + 40
	AreaBundSaxony                      = 9 + 40
	AreaBundHanover                     = 10 + 40
	AreaBundWestphalia                  = 11 + 40
	AreaBundHesse                       = 12 + 40
	AreaBundRhineProvince               = 13 + 40
	AreaBundUpperBavaria                = 14 + 40
	AreaBundLowerBavariaUpperPalatinate = 15 + 40
	AreaBundRhinelandPalatinate         = 16 + 40
	AreaBundSaarland                    = 17 + 40
	AreaBundUpperAndMiddleFranconia     = 18 + 40
	AreaBundHamburg                     = 19 + 40
	AreaBundLowerFranconia              = 20 + 40
	AreaBundSwabia                      = 21 + 40
	// 62
	AreaBundWurttemberg       = 23 + 40
	AreaBundBaden             = 24 + 40
	AreaBundBerlin            = 25 + 40
	AreaBundSchleswigHolstein = 26 + 40
	// 67
	AreaBundOldenburgBremen = 28 + 40
	AreaBundBraunschweig    = 29 + 40
	// 70
	// 71
	// 72
	// 73
	// 74
	// 75
	// 76
	// 77
	AreaBundKnappschaftBahnSee_Bahn = 38 + 40
	AreaBundKnappschaftBahnSee_See  = 39 + 40

	AreaKnappschaftBahnSeeBerBreHamLoSaxSchleHolWestphalia = 80 // ik the name is whack, anything else would've been too long tho
	AreaKnappschaftBahnSeeHesseRhineProvinz                = 81
	AreaKnappschaftBahnSeeBaWuBavariaRhinePalatSaar        = 82
	// 83
	// 84
	// 85
	// 86
	// 87
	// 88
	AreaKnappschaftBahnSeeBrandMeckWesPomSaxAnhSaxThu = 89
)

https://www.gesetze-im-internet.de/vkvv/anlage.html 2023-01-21

Variables

View Source
var (
	ErrLength = errors.New("de/pin: pension insurance numbers must be 12 digits long")

	ErrAreaCodeSyntax    = errors.New("de/pin: area codes must only contain digits")
	ErrAreaCodeInvalid   = errors.New("de/pin: invalid area code")
	ErrBirthDay          = errors.New("de/pin: the birthday must only contain digits")
	ErrBirthMonth        = errors.New("de/pin: the birth month must be a number between '01' and '12'")
	ErrBirthYear         = errors.New("de/pin: the birth year must contain only digits")
	ErrLastNameLetter    = errors.New("de/pin: the last name letter must be an ascii letter")
	ErrSerialNumber      = errors.New("de/pin: the serial number must contain only digits")
	ErrCheckDigitSyntax  = errors.New("de/pin: the check digit must be a digit")
	ErrCheckDigitInvalid = errors.New("de/pin: invalid check digit")
)

Functions

func IsValid

func IsValid(s string) bool

Types

type AreaCode

type AreaCode uint8

func (AreaCode) IsValid

func (c AreaCode) IsValid() bool

func (AreaCode) String

func (c AreaCode) String() string

type PensionInsuranceNumber

type PensionInsuranceNumber struct {
	// AreaCode is the area code of the pension insurance number.
	AreaCode AreaCode
	// BirthDay is the birthday of the holder of the pension insurance number.
	//
	// It may not necessarily reflect the actual birthday of the holder, if
	// there are more than 50 people with the same date of birth in the same
	// area with the same first letter of the last name, and the same serial
	// number group.
	// Should that be the case, then BirthDay is the BirthDay will be a number
	// greater than 31.
	BirthDay uint8
	// BirthMonth is the birth month of the holder of the pension insurance
	// number.
	BirthMonth uint8
	// BirthYear are the last two digits of the birth year of the holder of the
	// pension insurance number.
	BirthYear uint8
	// LastNameLetter is the first letter of the last name of the holder of the
	// pension insurance number.
	LastNameLetter rune
	// SerialNumber is the serial number of the pension insurance number.
	//
	// A number between 0 and 49 indicates the holder identified as male when
	// applying for the pension insurance number.
	// A number between 50 and 99 indicates the holder identified as female
	// or non-binary ('divers') when applying for the pension insurance number.
	SerialNumber uint8
	CheckDigit   uint8
}

func Parse

Parse parses the passed pension insurance number.

It ignores spaces and '/'.

Parse is case-insensitive, however, the case of letters in the returned PensionInsuranceNumber will always be uppercase.

If Parse returns without an error, the pension insurance number is considered syntactically valid.

func (PensionInsuranceNumber) Birthdate

func (pin PensionInsuranceNumber) Birthdate() time.Time

Birthdate returns the assumed birthday of the holder of the pension insurance number.

The returned time will use UTC as its location, because a) just because a person has a German pension insurance number, it does not mean they were born in the Europe/Berlin timezone, and b) birthdays are regarded as timezone-agnostic (i.e. just because a person was born on the 2nd of the month at 2am in New Zealand, that does not mean that they would celebrate their birthday on the 1st when they are in Germany, although that would be the correct day considering the timezone).

Inaccuracies

Birthdate may fail to return an accurate birthday, in any of these cases:

  1. The pension insurance number is invalid. In this case, Birthdate returns the zero value of time.Time. You can use time.Time.IsZero to check if that is the case.

    Note that Birthdate will not perform a full validity check. Currently, the only case where Birthdate will return a zero time, is when BirthDay is zero, or BirthMonth is outside the valid 1-12 range.

  2. The pension insurance number is valid, but the birthday cannot be determined, because of the special case described in doc of the BirthDay field. In this case, Birthdate returns a valid time that uses the first of the month as day. Check if BirthDay > 31 to determine if this is the case.

  3. The pension insurance number holder is 100 years or older. Since the BirthYear is only two digits, it is not possible to determine the correct century. Birthdate will attempt to guess it, by assuming that the holder is younger than 100 years and picking the century the appropriate century.

func (PensionInsuranceNumber) Compact added in v0.5.0

func (pin PensionInsuranceNumber) Compact() string

Compact renders a compact representation of the pension insurance number.

In contrast to String(), MarshalText does not add spaces between the different parts of the pension insurance number.

The returned string will have the following format:

AADDMMYYLSSC

func (PensionInsuranceNumber) MarshalText

func (pin PensionInsuranceNumber) MarshalText() ([]byte, error)

func (PensionInsuranceNumber) String

func (pin PensionInsuranceNumber) String() string

String pretty-prints the pension insurance number, adding spaces between area code, birthday, first letter of last name, and serial number.

The returned string will have the following format:

AA DDMMYY L SSC

func (*PensionInsuranceNumber) UnmarshalText

func (pin *PensionInsuranceNumber) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL