-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmbg.go
48 lines (41 loc) · 916 Bytes
/
jmbg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package jmbg
import (
"time"
"github.com/dusnm/jmbg/checksum"
"github.com/dusnm/jmbg/digits"
"github.com/dusnm/jmbg/dob"
"github.com/dusnm/jmbg/region"
"github.com/dusnm/jmbg/sex"
)
type (
JMBG struct {
Number string `json:"number"`
Digits [13]uint `json:"digits"`
DateOfBirth time.Time `json:"date_of_birth"`
Region region.Region `json:"region"`
Sex sex.Sex `json:"sex"`
Checksum checksum.Checksum `json:"checksum"`
}
)
func New(jmbg string) (JMBG, error) {
d, err := digits.New(jmbg)
if err != nil {
return JMBG{}, err
}
date, err := dob.New(d)
if err != nil {
return JMBG{}, err
}
r, err := region.New(d)
if err != nil {
return JMBG{}, err
}
return JMBG{
Number: jmbg,
Digits: d,
DateOfBirth: date,
Region: r,
Sex: sex.New(d),
Checksum: checksum.New(d),
}, nil
}