forked from Dwarfartisan/gisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
38 lines (35 loc) · 918 Bytes
/
time.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
package gisp
import (
tm "time"
px "github.com/Dwarfartisan/goparsec/parsex"
)
// Time 包引入了go的time包功能
var Time = Toolkit{
Meta: map[string]interface{}{
"category": "toolkit",
"name": "time",
},
Content: map[string]interface{}{
"now": SimpleBox{
ParsexSignChecker(px.Eof),
func(args ...interface{}) Tasker {
return func(env Env) (interface{}, error) {
return tm.Now(), nil
}
}},
"parseDuration": SimpleBox{
ParsexSignChecker(px.Bind_(StringValue, px.Eof)),
func(args ...interface{}) Tasker {
return func(env Env) (interface{}, error) {
return tm.ParseDuration(args[0].(string))
}
}},
"parseTime": SimpleBox{
ParsexSignChecker(px.Binds_(StringValue, StringValue, px.Eof)),
func(args ...interface{}) Tasker {
return func(env Env) (interface{}, error) {
return tm.Parse(args[0].(string), args[1].(string))
}
}},
},
}