-
Notifications
You must be signed in to change notification settings - Fork 6
/
option.go
53 lines (47 loc) · 1.65 KB
/
option.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
package cron
// SetLogger allows the expression descriptor to output log via logger.
func SetLogger(logger Logger) Option {
return func(exprDesc *ExpressionDescriptor) {
exprDesc.logger = logger
}
}
// Verbose sets the expression descriptor to output string in verbose format or not.
//
// Example: cronExpression = "* * 5 * * * *"
// - verbose = false: Every second, between 05:00 and 05:59
// - verbose = true: Every second, every minute, between 05:00 and 05:59, every day
func Verbose(v bool) Option {
return func(exprDesc *ExpressionDescriptor) {
exprDesc.isVerbose = v
}
}
// DayOfWeekStartsAtOne configures first day of the week is Monday (index 1) or Sunday (index 0, default).
func DayOfWeekStartsAtOne(v bool) Option {
return func(exprDesc *ExpressionDescriptor) {
exprDesc.isDOWStartsAtOne = v
}
}
// Use24HourTimeFormat configures the expression descriptor to output time in 24-hour format (14:00) or
// 12-hour format (2PM, default).
func Use24HourTimeFormat(v bool) Option {
return func(exprDesc *ExpressionDescriptor) {
exprDesc.is24HourTimeFormat = v
}
}
// SetLocales initializes the list of initial locales that the expression descriptor will output in.
// By default, the expression descriptor always initialize English (Locale_en).
func SetLocales(locales ...LocaleType) Option {
return func(exprDesc *ExpressionDescriptor) {
loaders, err := NewLocaleLoaders(locales...)
if err != nil {
exprDesc.log("failed to init locale loaders: %s", err)
return
}
if exprDesc.locales == nil {
exprDesc.locales = make(map[LocaleType]Locale)
}
for _, loader := range loaders {
exprDesc.locales[loader.GetLocaleType()] = loader
}
}
}