Skip to content

Commit

Permalink
Merge pull request #9 from hwf1324/Update-sxtwl
Browse files Browse the repository at this point in the history
更新 sxtwl
  • Loading branch information
cary-rowen authored Dec 3, 2023
2 parents 943e2c6 + 25e45f8 commit b2ea89e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 29 deletions.
Binary file not shown.
Binary file modified addon/globalPlugins/clipboardEnhancement/_sxtwl.cp37-win32.pyd
Binary file not shown.
62 changes: 39 additions & 23 deletions addon/globalPlugins/clipboardEnhancement/calendar.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import time
from . import sxtwl
from . import constants

from . import constants, sxtwl


def getTime():
d = time.localtime()
return f'{d.tm_hour}{d.tm_min}{d.tm_sec}秒'


def getDate():
d = time.localtime()
return f'{d.tm_year}{d.tm_mon}{d.tm_mday}日,星期{constants.WeekCn[d.tm_wday]}, 第{d.tm_yday}天'


def get_jieqi_time(day):
# 当日是否有节气
if day.hasJieQi():
#获取节气的儒略日数
# 获取节气的儒略日数
jd = day.getJieQiJD()
# 将儒略日数转换成年月日时秒
t = sxtwl.JD2DD(jd )
t = sxtwl.JD2DD(jd)
# 注意,t.s是小数,需要四舍五入
tt = "时刻:%d:%d:%d"%(t.h, t.m, round(t.s))
tt = "时刻:%d:%d:%d" % (t.h, t.m, round(t.s))
return f'今日{constants.jqmc[day.getJieQi()]}, {tt}'
else:
for i in range(2,32):
for i in range(2, 32):
day = day.before(1)
if day.hasJieQi():
jq = constants.jqmc[day.getJieQi()]
return f'{jq}{i}天'


def get_lunar_month_days(day):
# 一个农历月的天数
year = day.getLunarYear(False)
Expand All @@ -39,29 +43,31 @@ def get_lunar_month_days(day):

def get_lunar_date(day):
# 以立春为界的农历
s = "%s%s月%s" % (#day.getLunarYear(False),
'闰' if day.isLunarLeap() else '', constants.Ymc[day.getLunarMonth()], constants.rmc[day.getLunarDay()-1])
# s = s + '\n今日 %s %s' % (constants.jqmc[day.getJieQi()], tt)
s = "%s%s月%s" % ( # day.getLunarYear(False),
'闰' if day.isLunarLeap() else '', constants.Ymc[day.getLunarMonth()], constants.rmc[day.getLunarDay() - 1])
# s = s + '\n今日 %s %s' % (constants.jqmc[day.getJieQi()], tt)
return s


def get_gz(day, tm):
# 以立春为界的天干地支 (注,如果没有传参,或者传false,是以立春为界的。刚好和getLunarYear相反)
yTG = day.getYearGZ()
# 年干支
ygz = constants.Gan[yTG.tg] + constants.Zhi[yTG.dz]
shx = "生肖:" + constants.ShX[yTG.dz]
#月干支
# 月干支
mTG = day.getMonthGZ()
mgz = constants.Gan[mTG.tg] + constants.Zhi[mTG.dz]
#日干支
dTG = day.getDayGZ()
# 日干支
dTG = day.getDayGZ()
dgz = constants.Gan[dTG.tg] + constants.Zhi[dTG.dz]
#时干支,传24小时制的时间,分早晚子时
# 时干支,传24小时制的时间,分早晚子时
hour = tm.tm_hour
sTG = day.getHourGZ(hour)
sgz = constants.Gan[sTG.tg] + constants.Zhi[sTG.dz]
return f'{ygz}年,{mgz}月,{dgz}日,{sgz}时。\n{shx}'


def get_jieqi_before(day):
while True:
day = day.before(1)
Expand All @@ -71,6 +77,7 @@ def get_jieqi_before(day):
jqDay = '农历' + get_lunar_date(day)
return f'{day.getSolarMonth()}{day.getSolarDay()}{jq}, {jqDay}'


def get_jieqi_after(day):
while True:
day = day.after(1)
Expand All @@ -79,6 +86,7 @@ def get_jieqi_after(day):
jqDay = '农历' + get_lunar_date(day)
return f'{day.getSolarMonth()}{day.getSolarDay()}{jq}, {jqDay}'


'''
1.获取某日的前几天或者后几天的信息 (可以用到很多场景中)
# 获取某天的后面几天
Expand Down Expand Up @@ -128,7 +136,7 @@ def get_jieqi_after(day):
break
1.四柱反查 (好像还有bug,待修复)
# 四柱反查工具方法
# 实际项目中不要这样子搞哈,因为汉字utf-8,GBK2312不同的编码。建议还是直接使用天干地支的数字索引
# 实际项目中不要这样子搞哈,因为汉字utf-8,GBK2312不同的编码。建议还是直接使用天干地支的数字索引
def getGZ(gzStr):
tg = -1
dz = -1
Expand All @@ -139,7 +147,7 @@ def getGZ(gzStr):
for i, v in enumerate(constants.Zhi):
if gzStr[1] == v:
dz = i
break
break
return sxtwl.GZ(tg, dz)
# 四注反查 分别传的是年天干,月天干,日天干,时天干, 开始查询年,结束查询年 返回满足条件的儒略日数
jds = sxtwl.siZhu2Year(getGZ('辛丑'), getGZ('己亥'), getGZ('丙寅'), getGZ('癸巳'), 2003, 2029);
Expand All @@ -148,27 +156,35 @@ def getGZ(gzStr):
print("符合条件的时间:%d-%d-%d %d:%d:%d"%(t.Y, t.M, t.D, t.h, t.m, round(t.s)))
'''


def makeDay():
tm = time.localtime() #返回的是命名元组
tm = time.localtime() # 返回的是命名元组
# 从公历年月日获取一天的信息
day = sxtwl.fromSolar(tm.tm_year, tm.tm_mon, tm.tm_mday)
# 从农历年月日获取一天的信息
# day = sxtwl.fromLunar(2020, 12, 1)
return day, tm


def getLunarDate():
day, tm = makeDay()
return '。\n'.join((get_lunar_date(day),
return '。\n'.join((
get_lunar_date(day),
get_lunar_month_days(day),
get_gz(day, tm)))
get_gz(day, tm)
))


def getJieQi():
day, tm = makeDay()
return '。\n'.join((get_jieqi_time(day),
day, _ = makeDay()
return '。\n'.join([
get_jieqi_time(day),
get_jieqi_before(day),
get_jieqi_after(day)))
get_jieqi_after(day)
])


def get_constellation():
# 星座(有bug?待修复)
day,tm = makeDay()
return constants.XiZ[day.getConstellation()]+'座'
day, _ = makeDay()
return constants.XiZ[day.getConstellation()] + '座'
48 changes: 42 additions & 6 deletions addon/globalPlugins/clipboardEnhancement/sxtwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,51 @@ def capacity(self):
class Time(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
__repr__ = _swig_repr

def __init__(self, *args):
_sxtwl.Time_swiginit(self, _sxtwl.new_Time(*args))
Y = property(_sxtwl.Time_Y_get, _sxtwl.Time_Y_set)
M = property(_sxtwl.Time_M_get, _sxtwl.Time_M_set)
D = property(_sxtwl.Time_D_get, _sxtwl.Time_D_set)
h = property(_sxtwl.Time_h_get, _sxtwl.Time_h_set)
m = property(_sxtwl.Time_m_get, _sxtwl.Time_m_set)
s = property(_sxtwl.Time_s_get, _sxtwl.Time_s_set)

def __init__(self):
_sxtwl.Time_swiginit(self, _sxtwl.new_Time())
def getYear(self):
return _sxtwl.Time_getYear(self)

def setYear(self, year):
return _sxtwl.Time_setYear(self, year)

def setMonth(self, month):
return _sxtwl.Time_setMonth(self, month)

def getMonth(self):
return _sxtwl.Time_getMonth(self)

def getDay(self):
return _sxtwl.Time_getDay(self)

def setDay(self, day):
return _sxtwl.Time_setDay(self, day)

def getHour(self):
return _sxtwl.Time_getHour(self)

def setHour(self, hour):
return _sxtwl.Time_setHour(self, hour)

def getMin(self):
return _sxtwl.Time_getMin(self)

def setMour(self, min):
return _sxtwl.Time_setMour(self, min)

def getSec(self):
return _sxtwl.Time_getSec(self)

def setSec(self, sec):
return _sxtwl.Time_setSec(self, sec)
__swig_destroy__ = _sxtwl.delete_Time

# Register Time in _sxtwl:
Expand Down Expand Up @@ -298,8 +334,8 @@ def getMonthGZ(self):
def getDayGZ(self):
return _sxtwl.Day_getDayGZ(self)

def getHourGZ(self, hour):
return _sxtwl.Day_getHourGZ(self, hour)
def getHourGZ(self, hour, isZaoWanZiShi=True):
return _sxtwl.Day_getHourGZ(self, hour, isZaoWanZiShi)

def isLunarLeap(self):
return _sxtwl.Day_isLunarLeap(self)
Expand Down Expand Up @@ -351,8 +387,8 @@ def fromLunar(year, month, day, isRun=False):
def siZhu2Year(year, yue, ri, shi, fromYear, toYear):
return _sxtwl.siZhu2Year(year, yue, ri, shi, fromYear, toYear)

def getShiGz(dayTg, hour):
return _sxtwl.getShiGz(dayTg, hour)
def getShiGz(dayTg, hour, isZaoWanZiShi=True):
return _sxtwl.getShiGz(dayTg, hour, isZaoWanZiShi)

def getRunMonth(By):
return _sxtwl.getRunMonth(By)
Expand Down

0 comments on commit b2ea89e

Please sign in to comment.