-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
50 lines (42 loc) · 932 Bytes
/
options.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
package goliday
import "time"
// Option configures holiday search.
type Option func(*evaluateOption)
type evaluateOption struct {
year int
month int
day int
}
func newEvaluateOption() *evaluateOption {
return &evaluateOption{
year: -1,
month: -1,
day: -1,
}
}
// WithYear returns an option that sets the year.
func WithYear(year int) Option {
return func(e *evaluateOption) {
e.year = year
}
}
// WithMonth returns an option that sets the month.
func WithMonth(month int) Option {
return func(e *evaluateOption) {
e.month = month
}
}
// WithDay returns an option that sets the day.
func WithDay(day int) Option {
return func(e *evaluateOption) {
e.day = day
}
}
// WithTime returns an option that sets the year and month and day from time.Time instance.
func WithTime(t *time.Time) Option {
return func(e *evaluateOption) {
e.year = t.Year()
e.month = int(t.Month())
e.day = t.Day()
}
}