Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sxtwl 2.0.4 使用ymc, rmc 有問題 - Python3.10.0 #29

Open
samtptw opened this issue Dec 1, 2021 · 4 comments
Open

sxtwl 2.0.4 使用ymc, rmc 有問題 - Python3.10.0 #29

samtptw opened this issue Dec 1, 2021 · 4 comments

Comments

@samtptw
Copy link

samtptw commented Dec 1, 2021

import sxtwl #sxtwl 使用版本 2.0.4
import datetime

Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
ShX = ["鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "猪"]
numCn = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "驚蟄", "春分", "清明", "穀雨", "立夏", "小滿", "芒種", "夏至", "小暑", "大暑", "立秋", "處暑","白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"]
ymc = ["十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十" ]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
XiZ = ['摩羯', '水瓶', '双魚', '白羊', '金牛', '双子', '巨蟹', '狮子', '處女', '天秤', '天蝎', '射手']
WeekCn = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]

dt=datetime.datetime.now()
day=sxtwl.fromSolar(dt.year,dt.month,dt.day)
print("目前日期:", datetime.date.today())

if day.isLunarLeap():
print("農曆 閏",day.getLunarMonth(),"月", day.getLunarDay(),"日")
else:
print("農曆",day.getLunarMonth(),"月", day.getLunarDay(),"日")

if day.isLunarLeap():
print("農曆 閏",ymc[day.getLunarMonth()],"月", rmc[day.getLunarDay()],"日")
else:
print("農曆",ymc[day.getLunarMonth()],"月", rmc[day.getLunarDay()],"日")


目前日期: 2021-12-01
農曆 10 月 27 日
農曆 九 月 廿八 日

使用ymc, rmc 得到的中文日期為不正確

@yuangu
Copy link
Owner

yuangu commented Dec 2, 2021

ymc和rmc确实写错了。晚点我会修改例子。谢谢 !!话说你有微信么? 加群一起讨论啊,群二维码已经发至您的邮箱了。

@samtptw
Copy link
Author

samtptw commented Dec 3, 2021

今天改寫了一下, 有點笨的寫法, 暫時解決, 請參考:

import sxtwl #sxtwl 使用版本 2.0.4
import datetime

Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
ShX = ["鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "猪"]
numCn = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "驚蟄", "春分", "清明", "穀雨", "立夏", "小滿", "芒種", "夏至", "小暑", "大暑", "立秋", "處暑","白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"]
ymc = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十","十一", "十二"]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
XiZ = ['摩羯', '水瓶', '双魚', '白羊', '金牛', '双子', '巨蟹', '狮子', '處女', '天秤', '天蝎', '射手']
WeekCn = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]

def find_Chinese(time,value,unit=""): #ymc/rmc,尋找值(月/日),單位(月/日)
for i,j in enumerate(time,start=1):
if value==i:
return j+unit

dt=datetime.datetime.now()
#day=sxtwl.fromSolar(dt.year,dt.month,dt.day)
day=sxtwl.fromSolar(2020,5,26) #2020/5/26 農曆閏月
#print("目前日期:", datetime.date.today())
print("陽曆:",day.getSolarYear(), day.getSolarMonth(),day.getSolarDay())

if day.isLunarLeap():
print("農曆 閏",find_Chinese(ymc,day.getLunarMonth(),"月"), find_Chinese(rmc,day.getLunarDay(),"日"))
else:
print("農曆",find_Chinese(ymc,day.getLunarMonth(),"月"), find_Chinese(rmc,day.getLunarDay(),"日"))

========================================================================
陽曆: 2020 5 26
農曆 閏 四月 初四日

@yuangu
Copy link
Owner

yuangu commented Dec 3, 2021

不用这麻烦
直接月和日减一来做索引。

s = "农历:%d年%s%d月%d日" % (day.getLunarYear(False), '闰' if day.isLunarLeap() else '', ymc[day.getLunarMonth() - 1], rmc[day.getLunarDay() - 1])
print(s)

@samtptw
Copy link
Author

samtptw commented Dec 3, 2021

之前試過, 1月時有試到out of range 情形, 直接用ymc[day.getLunarMonth()]. 但是改為ymc[day.getLunarMonth() - 1], rmc[day.getLunarDay() - 1] 就沒有out of range這問題.

另外, 注意一下, 上面的ymc 已改為正月為首, 舊版是11月為首.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants