-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
65 lines (51 loc) · 1.27 KB
/
types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package rnokpp
import (
"fmt"
mathRand "math/rand"
"time"
"github.com/fre5h/rnokpp/internal"
)
// Gender is a string type representing a gender (male/female)
type Gender string
const Male = Gender("male")
const Female = Gender("female")
// String returns string representation of gender
func (g Gender) String() string {
return string(g)
}
// IsMale checks if gender is male
func (g Gender) IsMale() bool {
return g == Male
}
// IsFemale checks if gender is female
func (g Gender) IsFemale() bool {
return g == Female
}
// RandomGender returns random gender
func RandomGender() Gender {
if mathRand.Intn(2) == 0 {
return Female
}
return Male
}
// Details is a struct representing details of RNOKPP
type Details struct {
Valid bool
Gender Gender
Birthday time.Time
}
// String returns string representation of RNOKPP details
func (d Details) String() string {
if !d.Valid {
return "invalid"
}
return fmt.Sprintf("valid, %s, %s", d.Gender, d.Birthday.Format("02.01.2006"))
}
// NewDetails creates Details, and returns the pointer to it
func NewDetails(valid bool, gender Gender, date string) *Details {
birthday, err := time.ParseInLocation("02.01.2006", date, internal.BaseLocation)
if err != nil {
panic(err)
}
return &Details{valid, gender, birthday}
}