forked from neotoolkit/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.go
105 lines (98 loc) · 2.3 KB
/
date.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package faker
import "time"
// Weekday returns random weekday
func (f *Faker) Weekday() string {
return Weekday(
WithRand(f.cfg.rand),
WithWeekdays(f.cfg.weekdays...),
)
}
// Weekday returns random weekday
//
// faker.Weekday(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithWeekdays(
// "Sunday",
// "Monday",
// "Tuesday",
// "Wednesday",
// "Thursday",
// "Friday",
// "Saturday",
// ), // Slice of weekday for RandomElement
// )
//
func Weekday(opts ...Option) string {
cfg := newConfig(opts...)
if len(cfg.weekdays) == 0 {
WithWeekdays(
time.Sunday.String(),
time.Monday.String(),
time.Tuesday.String(),
time.Wednesday.String(),
time.Thursday.String(),
time.Friday.String(),
time.Saturday.String(),
)(cfg)
}
return RandomElement(cfg.weekdays, opts...)
}
// Month returns random month
func (f *Faker) Month() string {
return Month(
WithRand(f.cfg.rand),
WithMonths(f.cfg.months...),
)
}
// Month returns random month
//
// faker.Month(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithMonths(
// "January",
// "February",
// "March",
// "April",
// "May",
// "June",
// "July",
// "August",
// "September",
// "October",
// "November",
// "December",
// ), // Slice of month for RandomElement
// )
func Month(opts ...Option) string {
cfg := newConfig(opts...)
if len(cfg.months) == 0 {
WithMonths(
time.January.String(),
time.February.String(),
time.March.String(),
time.April.String(),
time.May.String(),
time.June.String(),
time.July.String(),
time.August.String(),
time.September.String(),
time.October.String(),
time.November.String(),
time.December.String(),
)(cfg)
}
return RandomElement(cfg.months, opts...)
}
// Year returns random year between 1970 and current local
func (f *Faker) Year() int {
return Integer(1970, time.Now().Year(), WithRand(f.cfg.rand))
}
// Year returns random year between 1970 and current local
//
// faker.Year(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// )
//
func Year(opts ...Option) int {
return Integer(1970, time.Now().Year(), opts...)
}