-
Notifications
You must be signed in to change notification settings - Fork 16
/
calendar_test.go
158 lines (126 loc) · 3.17 KB
/
calendar_test.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package gocalendar
import (
"encoding/json"
"fmt"
"testing"
"time"
)
func TestDefaultCalendar(t *testing.T) {
c := DefaultCalendar()
t.Log(c.config.Grid)
}
func TestNewCalendar(t *testing.T) {
cfg := CalendarConfig{
Grid:1,
TimeZoneName:"Europe/Berlin",
}
c := NewCalendar(cfg)
ti := c.GetRawTime()
t.Log(ti.Zone())
t.Log(ti.String())
}
// 一整年节气
func TestCalendar_SolarTerms(t *testing.T) {
c := NewCalendar(CalendarConfig{TimeZoneName:"Asia/Shanghai"})
sts:= c.SolarTerms(2021)
for _,v := range sts{
st := fmt.Sprintf(" %s 定%s:%s", v.Name, v.Name, v.Time.Format(time.RFC3339))
t.Log(st)
}
}
func TestCalendar_GenerateWithDate(t *testing.T) {
beforeTime := time.Now()
defer func() {
str := time.Since(beforeTime)
t.Logf("本次执行用时:%s\n",str)
}()
c := NewCalendar(CalendarConfig{
Grid:GridWeek,
FirstWeek:0,
SolarTerms:true,
Lunar:true,
HeavenlyEarthly:true,
NightZiHour:true,
StarSign:true,
})
result := c.GenerateWithDate(2021,12,22)
for _,item := range result {
fmt.Println(item)
}
t.Log("----------------------------")
items := c.NextMonth()
for _,item := range items {
fmt.Println(item)
}
}
func TestCalendar_Generate(t *testing.T) {
beforeTime := time.Now()
defer func() {
str := time.Since(beforeTime)
t.Logf("本次执行用时:%s\n",str)
}()
c := NewCalendar(CalendarConfig{
Grid:GridMonth,
FirstWeek:0,
SolarTerms:true,
Lunar:true,
HeavenlyEarthly:true,
NightZiHour:true,
StarSign:true,
})
c.SetRawTime(2021,2,1)
result := c.Generate()
for _,item := range result {
// t.Log(item)
fmt.Println(item)
}
}
// 一周日历表
func TestCalendar_weekCalendar(t *testing.T) {
beforeTime := time.Now()
defer func() {
str := time.Since(beforeTime)
t.Logf("本次执行用时:%s\n",str)
}()
c := NewCalendar(CalendarConfig{Grid:GridWeek,FirstWeek:0,SolarTerms:true,Lunar:true,HeavenlyEarthly:true,NightZiHour:true})
c.weekCalendar()
for _,item := range c.Items {
t.Log(item)
}
}
// 一月日历表
func TestCalendar_monthCalendar(t *testing.T) {
beforeTime := time.Now()
defer func() {
str := time.Since(beforeTime)
t.Logf("本次执行用时:%s\n",str)
}()
c := NewCalendar(CalendarConfig{Grid:GridMonth,FirstWeek:0,TimeZoneName:"Asia/Shanghai",SolarTerms:true,Lunar:true,HeavenlyEarthly:true,NightZiHour:true,StarSign:true})
c.SetRawTime(2021,12,1)
items := c.monthCalendar()
itemsJson,_ := json.Marshal(items)
t.Log(string(itemsJson))
for _,item := range items {
t.Log(item)
}
t.Logf("st len=%d jSS len=%d qSS len=%d tNM len=%d lMC len=%d lMD len=%d lFD len=%d gFD len=%d",len(c.tempData.st.data),len(c.tempData.jSS.data),len(c.tempData.qSS.data),len(c.tempData.tNM.data),len(c.tempData.lMC.data),len(c.tempData.lMD.data),len(c.tempData.lFD.data),len(c.tempData.gFD.data))
}
// 星座
func TestStarSign(t *testing.T) {
i,ss,_ := StarSign(5,6)
if i == 3 {
t.Log("passed")
}else{
t.Error(i,ss)
}
}
// Benchmark
func BenchmarkCalendar_monthCalendar(b *testing.B) {
c := DefaultCalendar()
c.monthCalendar()
}
// Benchmark
func BenchmarkCalendar_SolarTerms(b *testing.B) {
c := NewCalendar(CalendarConfig{TimeZoneName:"Asia/Shanghai"})
c.SolarTerms(2021)
}