forked from 6tail/lunar-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTao.py
More file actions
130 lines (102 loc) · 3.71 KB
/
Tao.py
File metadata and controls
130 lines (102 loc) · 3.71 KB
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
# -*- coding: utf-8 -*-
from . import Lunar, TaoFestival
from .util import LunarUtil, TaoUtil
class Tao:
"""
道历
"""
BIRTH_YEAR = -2697
def __init__(self, lunar):
self.__lunar = lunar
@staticmethod
def fromLunar(lunar):
return Tao(lunar)
@staticmethod
def fromYmdHms(year, month, day, hour, minute, second):
return Tao.fromLunar(Lunar.fromYmdHms(year + Tao.BIRTH_YEAR, month, day, hour, minute, second))
@staticmethod
def fromYmd(year, month, day):
return Tao.fromYmdHms(year, month, day, 0, 0, 0)
def getLunar(self):
return self.__lunar
def getYear(self):
return self.__lunar.getYear() - Tao.BIRTH_YEAR
def getMonth(self):
return self.__lunar.getMonth()
def getDay(self):
return self.__lunar.getDay()
def getYearInChinese(self):
y = str(self.getYear())
s = ""
for i in range(0, len(y)):
s += LunarUtil.NUMBER[ord(y[i]) - 48]
return s
def getMonthInChinese(self):
return self.__lunar.getMonthInChinese()
def getDayInChinese(self):
return self.__lunar.getDayInChinese()
def getFestivals(self):
festivals = []
md = "%d-%d" % (self.getMonth(), self.getDay())
if md in TaoUtil.FESTIVAL:
fs = TaoUtil.FESTIVAL[md]
for f in fs:
festivals.append(f)
jq = self.__lunar.getJieQi()
if "冬至" == jq:
festivals.append(TaoFestival("元始天尊圣诞"))
elif "夏至" == jq:
festivals.append(TaoFestival("灵宝天尊圣诞"))
# 八节日
if jq in TaoUtil.BA_JIE:
festivals.append(TaoFestival(TaoUtil.BA_JIE[jq]))
# 八会日
gz = self.__lunar.getDayInGanZhi()
if gz in TaoUtil.BA_HUI:
festivals.append(TaoFestival(TaoUtil.BA_HUI[gz]))
return festivals
def __isDayIn(self, days):
md = "%d-%d" % (self.getMonth(), self.getDay())
for d in days:
if md == d:
return True
return False
def isDaySanHui(self):
return self.__isDayIn(TaoUtil.SAN_HUI)
def isDaySanYuan(self):
return self.__isDayIn(TaoUtil.SAN_YUAN)
def isDayBaJie(self):
return self.__lunar.getJieQi() in TaoUtil.BA_JIE
def isDayWuLa(self):
return self.__isDayIn(TaoUtil.WU_LA)
def isDayBaHui(self):
return self.__lunar.getDayInGanZhi() in TaoUtil.BA_HUI
def isDayMingWu(self):
return "戊" == self.__lunar.getDayGan()
def isDayAnWu(self):
return self.__lunar.getDayZhi() == TaoUtil.AN_WU[abs(self.getMonth()) - 1]
def isDayWu(self):
return self.isDayMingWu() or self.isDayAnWu()
def isDayTianShe(self):
ret = False
mz = self.__lunar.getMonthZhi()
dgz = self.__lunar.getDayInGanZhi()
if mz in "寅卯辰":
if "戊寅" == dgz:
ret = True
elif mz in "巳午未":
if "甲午" == dgz:
ret = True
elif mz in "申酉戌":
if "戊申" == dgz:
ret = True
elif mz in "亥子丑":
if "甲子" == dgz:
ret = True
return ret
def __str__(self):
return self.toString()
def toString(self):
return "%s年%s月%s" % (self.getYearInChinese(), self.getMonthInChinese(), self.getDayInChinese())
def toFullString(self):
return "道歷%s年,天运%s年,%s月,%s日。%s月%s日,%s時。" % (self.getYearInChinese(), self.__lunar.getYearInGanZhi(), self.__lunar.getMonthInGanZhi(), self.__lunar.getDayInGanZhi(), self.getMonthInChinese(), self.getDayInChinese(), self.__lunar.getTimeZhi())