chncal

apis

is_holiday

dramkit.chncal.apis.is_holiday(date=None)

check if one date is holiday in China. in other words, Chinese people get rest at that day.

Return type:

bool

is_workday

dramkit.chncal.apis.is_workday(date=None)

check if one date is workday in China. in other words, Chinese people works at that day.

Return type:

bool

is_in_lieu

dramkit.chncal.apis.is_in_lieu(date=None)

check if one date is in lieu in China. in other words, Chinese people get rest at that day because of legal holiday.

Return type:

bool

get_holiday_detail

dramkit.chncal.apis.get_holiday_detail(date=None)

check if one date is holiday in China, and return the holiday name (None if it’s a normal day)

Returns:

holiday bool indicator, and holiday name if it’s holiday related day

Return type:

(bool, str | None)

get_dates

dramkit.chncal.apis.get_dates(start, end=None)

get dates between start date and end date. (includes start date and end date)

Return type:

list[datetime.date]

get_holidays

dramkit.chncal.apis.get_holidays(start, end=None, include_weekends=True)

get holidays between start date and end date. (includes start date and end date)

Parameters:

include_weekends (bool) – False for excluding Saturdays and Sundays

Return type:

list[datetime.date]

get_workdays

dramkit.chncal.apis.get_workdays(start, end=None)

get workdays between start date and end date. (includes start date and end date)

Return type:

list[datetime.date]

find_workday

dramkit.chncal.apis.find_workday(delta_days=0, date=None)

find the workday after {delta_days} days.

Parameters:

delta_days (int) – 0 means next workday (includes today), -1 means previous workday.

Param:

the start point

Return type:

datetime.date

get_solar_terms

dramkit.chncal.apis.get_solar_terms(start=None, end=None)

生成24节气 通用寿星公式:https://www.jianshu.com/p/1f814c6bb475

通式寿星公式:[Y×D+C]-L []里面取整数;Y=年数的后2位数;D=0.2422;L=Y/4,小寒、大寒、立春、雨水的 L=(Y-1)/4

Parameters:
  • start (datetime.date) – 开始日期

  • end (datetime.date) – 结束日期

Return type:

list[(datetime.date, str)]

get_tgdz_year

dramkit.chncal.apis.get_tgdz_year(year=None)

计算(农历)年份天干地支

get_tgdz_date

dramkit.chncal.apis.get_tgdz_date(date=None)

根据公历日期计算农历干支纪日

get_tgdz_hour

dramkit.chncal.apis.get_tgdz_hour(time=None)

根据公历时间(小时)计算农历干支纪时

get_bazi

dramkit.chncal.apis.get_bazi(time=None)

根据公历时间生成八字

Examples

>>> get_bazi('1992.05.14 18:00')

get_bazi_lunar

dramkit.chncal.apis.get_bazi_lunar(time, run=False)
根据农历时间生成八字
time格式如’2023.02.30 19:30:20’,时分秒可以不写
run为True表示闰月日期

Examples

>>> get_bazi_lunar('2023.02.30')

get_wuxing

dramkit.chncal.apis.get_wuxing(time=None)

get_wuxing_lunar

dramkit.chncal.apis.get_wuxing_lunar(time, run=False)

get_zodiac_match

dramkit.chncal.apis.get_zodiac_match(time=None)

根据公历时间获取属相合婚信息

get_zodiac_match_lunar

dramkit.chncal.apis.get_zodiac_match_lunar(time, run=False)

根据农历时间获取属相合婚信息

fate_weight

dramkit.chncal.apis.fate_weight(time=None)

称命,传入公历时间

fate_weight_lunar

dramkit.chncal.apis.fate_weight_lunar(time, run=False)

称命,传入农历时间

Examples

>>> fate_weight_lunar('2023.02.30 09:30:00')

get_xingzuo

dramkit.chncal.apis.get_xingzuo(date=None)

获取星座

get_recent_workday

dramkit.chncal.apis.get_recent_workday(date=None, dirt='post')

若date为工作日,则返回,否则返回下一个(post)或上一个(pre)工作日

get_next_nth_workday

dramkit.chncal.apis.get_next_nth_workday(date=None, n=1)
给定日期date,返回其后第n个工作日日期,n可为负数(返回结果在date之前)
若n为0,直接返回date

get_work_dates

dramkit.chncal.apis.get_work_dates(start_date, end_date=None)

取指定起止日期内的工作日

is_tradeday

dramkit.chncal.apis.is_tradeday(date=None, market='SSE')

判断是否为交易日

get_recent_tradeday

dramkit.chncal.apis.get_recent_tradeday(date=None, dirt='post', market='SSE')

若date为交易日,则直接返回date,否则返回下一个(dirt=’post’)或上一个(dirt=’pre’)交易日

get_next_nth_tradeday

dramkit.chncal.apis.get_next_nth_tradeday(date=None, n=1, market='SSE')
给定日期date,返回其后第n个交易日日期,n可为负数(返回结果在date之前)
若n为0,直接返回date

get_trade_dates

dramkit.chncal.apis.get_trade_dates(start_date, end_date=None, market='SSE')

取指定起止日期内的交易日期(周内的工作日)

gen2lun

dramkit.chncal.apis.gen2lun(date=None)

公历日期转农历日期

gen2gz

dramkit.chncal.apis.gen2gz(date=None)

公历日期转干支纪日法

lun2gen

dramkit.chncal.apis.lun2gen(date, run=False)
农历日期转普通日期
date格式如’2023.02.30’
run为True表示闰月日期

Examples

>>> lun2gen('2023.02.30')

get_age_by_shuxiang

dramkit.chncal.apis.get_age_by_shuxiang(shuxiang, return_n=10)

根据属性获取可能年龄

constants

Holiday

class dramkit.chncal.constants.Holiday(value)

Bases: Enum

An enumeration.

anti_fascist_70th_day = 'Anti-Fascist 70th Day'
dragon_boat_festival = 'Dragon Boat Festival'
labour_day = 'Labour Day'
mid_autumn_festival = 'Mid-autumn Festival'
national_day = 'National Day'
new_years_day = "New Year's Day"
spring_festival = 'Spring Festival'
tomb_sweeping_day = 'Tomb-sweeping Day'

constants_fate

constants_hko

constants_trade_dates

constants_wuxing

constants_zodiac_marry

solar_terms

SolarTerms

class dramkit.chncal.solar_terms.SolarTerms(value)

Bases: Enum

中国24节气

code_dew = ('Cold Dew', '寒露')
frost_descent = ("Frost's Descent", '霜降')
grain_in_beard = ('Grain in Beard', '芒种')
grain_rain = ('Grain Rain', '谷雨')
greater_cold = ('Greater Cold', '大寒')
greater_heat = ('Greater Heat', '大暑')
greater_snow = ('Greater Snow', '大雪')
lesser_cold = ('Lesser Cold', '小寒')
lesser_fullness_of_grain = ('Lesser Fullness of Grain', '小满')
lesser_heat = ('Lesser Heat', '小暑')
lesser_snow = ('Lesser Snow', '小雪')
pure_brightness = ('Pure Brightness', '清明')
rain_water = ('Rain Water', '雨水')
the_autumn_equinox = ('the Autumn Equinox', '秋分')
the_beginning_of_autumn = ('the Beginning of Autumn', '立秋')
the_beginning_of_spring = ('the Beginning of Spring', '立春')
the_beginning_of_summer = ('the Beginning of Summer', '立夏')
the_beginning_of_winter = ('the Beginning of Winter', '立冬')
the_end_of_heat = ('the End of Heat', '处暑')
the_spring_equinox = ('the Spring Equinox', '春分')
the_summer_solstice = ('the Summer Solstice', '夏至')
the_waking_of_insects = ('the Waking of Insects', '惊蛰')
the_winter_solstice = ('the Winter Solstice', '冬至')
white_dew = ('White Dew', '白露')