-
Notifications
You must be signed in to change notification settings - Fork 16
/
clone.go
138 lines (118 loc) · 2.43 KB
/
clone.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
package gocalendar
// (*SolarTermItem) clone
func (sti *SolarTermItem) clone() *SolarTermItem {
if sti == nil {
return nil
}
t := sti.Time.AddDate(0, 0, 0)
return &SolarTermItem{
Index: sti.Index,
Name: sti.Name,
Time: &t,
}
}
// (*StarSignItem) clone
func (ssi *StarSignItem) clone() *StarSignItem {
if ssi == nil {
return nil
}
return &StarSignItem{
Index: ssi.Index,
Name: ssi.Name,
}
}
// (*FestivalItem) clone
func (fi *FestivalItem) clone() *FestivalItem {
if fi == nil {
return nil
}
var shows []string
var secondary []string
shows = append(shows, fi.Show...)
secondary = append(secondary, fi.Secondary...)
return &FestivalItem{
Show: shows,
Secondary: secondary,
}
}
// (*GZItem) clone
func (gzi *GZItem) clone() *GZItem {
if gzi == nil {
return nil
}
return &GZItem{
HSI: gzi.HSI,
HSN: gzi.HSN,
EBI: gzi.EBI,
EBN: gzi.EBN,
}
}
// (*GZ)clone
func (gz *GZ) clone() *GZ {
if gz == nil {
return nil
}
return &GZ{
Year: gz.Year.clone(),
Month: gz.Month.clone(),
Day: gz.Day.clone(),
Hour: gz.Hour.clone(),
}
}
// (*LunarDate) clone
func (ld *LunarDate) clone() *LunarDate {
if ld == nil {
return nil
}
return &LunarDate{
Year: ld.Year,
Month: ld.Month,
Day: ld.Day,
MonthName: ld.MonthName,
DayName: ld.DayName,
LeapStr: ld.LeapStr,
YearLeapMonth: ld.YearLeapMonth,
AnimalIndex: ld.AnimalIndex,
AnimalName: ld.AnimalName,
YearGZ: ld.YearGZ.clone(),
Festival: ld.Festival.clone(),
}
}
// (*CalendarItem) clone
func (ci *CalendarItem) clone() *CalendarItem {
if ci == nil {
return nil
}
t := ci.Time.AddDate(0, 0, 0)
return &CalendarItem{
Time: &t,
IsAccidental: ci.IsAccidental,
IsToday: ci.IsToday,
Festival: ci.Festival.clone(),
SolarTerm: ci.SolarTerm.clone(),
GZ: ci.GZ.clone(),
LunarDate: ci.LunarDate.clone(),
StarSign: ci.StarSign.clone(),
}
}
// (*Calendar) clone 克隆一个Calendar
// 该克隆不对临时数据克隆,而是清空临时数据
func (c *Calendar) Clone() *Calendar {
if c == nil {
return nil
}
rawT := c.rawTime.AddDate(0, 0, 0)
var items []*CalendarItem
if c.Items != nil {
for _, itemv := range c.Items {
items = append(items, itemv.clone())
}
}
return &Calendar{
Items: items,
config: c.config.clone(),
loc: c.loc,
rawTime: &rawT,
tempData: newCalendarTempData(),
}
}