CutePandaSh / zhdate

ZhDate **农历转换

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

建议 chinese 返回一个对象, 以便用于数据处理

chen-kay opened this issue · comments

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],
        )

好主意,妙啊

再增加一个返回类并没有意义,如果需要天干地支和生肖的单独数据,不如直接增加类里面的属性来提供。
chinese 方法的作用就是输出中文字符串的。

新手直接用字符串分割获取chinese里面的年份,日期,生肖等信息。