cutepandash / zhdate Goto Github PK
View Code? Open in Web Editor NEWZhDate **农历转换
License: GNU General Public License v3.0
ZhDate **农历转换
License: GNU General Public License v3.0
❯ python3
Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from zhdate import ZhDate
>>> ZhDate.today()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../venv/lib/python3.11/site-packages/zhdate/__init__.py", line 164, in today
return ZhDate.from_datetime(datetime.now())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../venv/lib/python3.11/site-packages/zhdate/__init__.py", line 160, in from_datetime
return ZhDate(lunar_year, lunar_month, lunar_day, leap_month)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../venv/lib/python3.11/site-packages/zhdate/__init__.py", line 111, in __init__
raise TypeError('农历日期不支持,超出农历1900年1月1日至2100年12月29日,或日期不存在')
TypeError: 农历日期不支持,超出农历1900年1月1日至2100年12月29日,或日期不存在
❯ pip install --upgrade zhdate
Requirement already satisfied: zhdate in ./venv/lib/python3.11/site-packages (0.1)
from pydantic import BaseModel
class ZhModel(BaseModel):
zh_year: str
zh_month: str
zh_day: str
year_tiandi: str
shengxiao: str
def __str__(self):
return f"{self.zh_year}{self.zh_month}{self.zh_day} {self.year_tiandi} ({self.shengxiao}年)"
class ZhDate1():
def chinese(self):
......
return ZhModel(
zh_year=zh_year,
zh_month=zh_month,
zh_day=zh_day,
year_tiandi=year_tiandi,
shengxiao=shengxiao[(self.lunar_year - 1900) % 12],
)
from datetime import datetime
from zhdate import ZhDate
print(ZhDate.from_datetime(datetime(2017, 8, 12)).chinese())
输出为:
二零一七年闰六月二十一 丁酉年 (鸡年)
其中的「二十一」 换成 「廿一」会不会好点。
from datetime import datetime
from zhdate import ZhDate
dt_date = datetime(2014,1,30,0,0,1)
date = ZhDate.from_datetime(dt_date) #会抛出异常
date = ZhDate.from_datetime(datetime.combine(dt_date.date(),datetime.min.time())) #必须处理掉时间部分才能正常使用
已发现存在bug的时间:
公历01/30/14
公历02/07/16
公历01/27/17
公历02/15/18
公历01/24/20
期待修正。
f字符串只支持python 3.6以上,希望标注清楚
希望作者再推出一个format版本
请问,方便把__format__() 写一下吗?
print(f"{zh_obj:>16}", flush=True)
这样的语法就会报错
TypeError: unsupported format string passed to ZhDate.format
非常感激
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.