swedishssn

package module
v0.0.0-...-b170fbd Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-swedishssn

Parsing of swedish social security numbers (personnummer).

Usage

package main

import (
    swedishssn "github.com/EClaesson/go-swedishssn"
)

// type SwedishSsn struct {
//     date   time.Time
//	   number string
// 	   sign   string
// }

func main() {
    // Creates a SwedishSsn from string (handles + sign for age >= 100)
    ssn, err := swedishssn.FromString("010203-1234")

    // String
    ssn.String() // => "20010203-1234"
    ssn.StringShort() // => "010203-1234"
    ssn.StringNoSign() // => "200102031234"
    ssn.StringShortNoSign() // => "0102031234"

    // Age now
    ssn.Age() // => 20

    // Age at specific time.Time
    ssn.AgeAt(time.Now()) // => 20

    // swedishssn.Male or swedishssn.Female
    ssn.Sex() // => swedishssn.Male

    // Luhn control digit check
    ssn.IsValid() // => true
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sex

type Sex int

Sex represents biological birth-sex according to SSN.

const (
	Male Sex = iota
	Female
)

Sex definitions

type SwedishSsn

type SwedishSsn struct {
	// contains filtered or unexported fields
}

SwedishSsn represents a swedish social security number (personnummer).

func FromString

func FromString(ssn string) (SwedishSsn, error)

FromString parses a SSN as string and creates a SwedishSsn.

func (SwedishSsn) Age

func (ssn SwedishSsn) Age() int

Age calculates the persons age at the current time.

func (SwedishSsn) AgeAt

func (ssn SwedishSsn) AgeAt(at time.Time) int

AgeAt calculates the persons age at a specific time.

func (SwedishSsn) IsValid

func (ssn SwedishSsn) IsValid() bool

IsValid checks that the ssn and control digit is valid.

func (SwedishSsn) Sex

func (ssn SwedishSsn) Sex() Sex

Sex calculates the persons birth-sex.

func (SwedishSsn) String

func (ssn SwedishSsn) String() string

String converts the SSN to a string with 4-digit year with separator sign.

func (SwedishSsn) StringNoSign

func (ssn SwedishSsn) StringNoSign() string

StringNoSign converts the SSN to a string with 4-digit year without separator sign.

func (SwedishSsn) StringShort

func (ssn SwedishSsn) StringShort() string

StringShort converts the SSN to a string with 2-digit year with separator sign.

func (SwedishSsn) StringShortNoSign

func (ssn SwedishSsn) StringShortNoSign() string

StringShortNoSign converts the SSN to a string with 2-digit year without separator sign.

Jump to

Keyboard shortcuts

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