forked from warrially/BaziGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyinyang.go
69 lines (57 loc) · 1.34 KB
/
yinyang.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
package bazi
// 阴阳
// 从柱里获取阴阳
// GetYinYangFromNumber (阴 == 0, 阳 == 1)
func GetYinYangFromNumber(nValue int) string {
switch nValue {
case 0:
return "阴"
case 1:
return "阳"
}
return ""
}
// func GetYinYangFromZhu(pZhu *TZhu) int {
// return (pZhu.Gan.Value + 1) % 2
// }
// NewYinYang 创建阴阳
func NewYinYang(nValue int) *TYinYang {
nValue %= 2
yinyang := TYinYang(nValue)
return &yinyang
}
// NewYinYangFromZhu 从柱里创建阴阳
func NewYinYangFromZhu(pZhu *TZhu) *TYinYang {
return NewYinYangFromGan(pZhu.Gan())
}
// NewYinYangFromGan 从干里创建阴阳
func NewYinYangFromGan(pGan *TGan) *TYinYang {
nGan := pGan.Value()
switch nGan {
// 甲丙戊庚壬 0, 2, 4, 6, 8 阳 (1)
case 0, 2, 4, 6, 8:
return NewYinYang(1)
// 乙丁己辛癸 1, 3, 5, 7, 9 阴 (0)
case 1, 3, 5, 7, 9:
return NewYinYang(0)
}
return nil
}
// TYinYang 阴阳
type TYinYang int
// ToString 转换成可阅读的字符串
func (m *TYinYang) ToString() string {
return m.String()
}
// ToInt 转换成int
func (m *TYinYang) ToInt() int {
return m.Value()
}
// Value 转换成int
func (m *TYinYang) Value() int {
return (int)(*m)
}
// String 转换成可阅读的字符串
func (m *TYinYang) String() string {
return GetYinYangFromNumber(m.Value())
}