-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdate.go
100 lines (79 loc) · 1.6 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
package stdlib
import (
"time"
"github.com/araddon/dateparse"
)
func dateYear(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Year())
}
func dateMonth(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Month())
}
func dateDay(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Day())
}
func dateYearDay(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.YearDay())
}
func dateHour(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Hour())
}
func dateMinute(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Minute())
}
func dateSecond(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return int64(t.Second())
}
func dateUnix(s string) int64 {
t, err := dateparse.ParseAny(s)
if err != nil {
return -1
}
return t.Unix()
}
func dateRfc3339(s string) string {
t, err := dateparse.ParseAny(s)
if err != nil {
return ""
}
return t.Format(time.RFC3339)
}
var dateFunctions = map[string]any{
"date_year": stringy1int64(dateYear),
"date_month": stringy1int64(dateMonth),
"date_day": stringy1int64(dateDay),
"date_yearday": stringy1int64(dateYearDay),
"date_hour": stringy1int64(dateHour),
"date_minute": stringy1int64(dateMinute),
"date_second": stringy1int64(dateSecond),
"date_unix": stringy1int64(dateUnix),
"date_rfc3339": stringy1string(dateRfc3339),
}