-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcuts.go
42 lines (36 loc) · 1.26 KB
/
shortcuts.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
package datetoken
import (
"github.com/sonirico/datetoken.go/evaluator"
"time"
)
// EvalNaive evaluates a token with default settings (TZ=UTC, weeks start on Sunday)
func EvalNaive(payload string) (time.Time, error) {
eva := evaluator.New()
return eva.Eval(payload)
}
// Eval evaluates a token for a give time zone and weekday, being the start of weeks configurable
func Eval(payload string, loc *time.Location, weekday time.Weekday) (time.Time, error) {
eva := evaluator.New()
eva.SetTZ(loc)
eva.SetWeeksStartDay(weekday)
return eva.Eval(payload)
}
// EvalIn evaluates a token for a given time zone, being Sunday the start of weeks
func EvalIn(payload string, loc *time.Location) (time.Time, error) {
eva := evaluator.New()
eva.SetTZ(loc)
return eva.Eval(payload)
}
// EvalWeekDay evaluates a token in UTC, being the start of a week configurable
func EvalWeekDay(payload string, weekday time.Weekday) (time.Time, error) {
eva := evaluator.New()
eva.SetWeeksStartDay(weekday)
return eva.Eval(payload)
}
// EvalCfg evaluates a token, allowing configuration by using any struct compliant with Config
func EvalCfg(payload string, cfg Config) (time.Time, error) {
eva := evaluator.New()
eva.SetTZ(cfg.Tz())
eva.SetWeeksStartDay(cfg.WeeksStartAt())
return eva.Eval(payload)
}