Comments (2)
- borax 可以解决 根据阳历(公历)生日计算在今天阴历(农历)生日 ,使用
LunarFestival
类即可 - 在现实生活中,有的只过一个生日,有的有过两个生日,都存在。
- 在编程实现中,可以也返回闰月的那个生日,毕竟同一个闰月出现比较少,最近闰四月是在2001、2012、2020、2058;也可以提供一个变量(如下面的leap_day_included ),控制是否显示闰月生日。
有关代码如下:
from datetime import date
from borax.calendars.lunardate import LunarDate
from borax.calendars.festivals2 import LunarFestival, Period
solar_birth = date(1994, 5, 21)
lunar_birth = LunarDate.from_solar(solar_birth) # 出生那天的农历日期
print(lunar_birth) # LunarDate(1994, 4, 11, 0)
# 农历生日对应的节日对象
lunar_birth_festival = LunarFestival(month=lunar_birth.month, day=lunar_birth.day)
# [<WrappedDate:2020-05-03(二〇二〇年四月十一)>, <WrappedDate:2020-06-02(二〇二〇年闰四月十一)>]
wd_list = lunar_birth_festival.list_days(*Period.lunar_year(2020))
leap_day_included = True
if not leap_day_included:
wd_list = [wd for wd in wd_list if wd.lunar.leap == 0] # 去掉其中的闰月日期
print(wd_list)
文档:https://borax.readthedocs.io/zh_CN/latest/guides/festivals2/
from borax.
收到,谢谢 @fastpx2014 🙏 🌹
from borax.
Related Issues (20)
- festivalfactory : 2017-08-21 day out of range HOT 1
- 农历:LunarDate.cn_day_calendar 计算错误%F 描述符缺少“月”后缀
- 农历日“二十”“三十”中文名称错误
- LunarDate.leap类型不一致
- LCalendars.create_solar_date在2101年时出现错误
- pylint代码静态检测结果
- 代码覆盖率分模块统计
- cjson和JsonResponse整合问题
- fetch对列表数据无效 HOT 1
- 新增星期型节日(WeekFestival)的两种情形
- 农历日期反向解析strptime函数
- 三伏天计算错误
- 新的节气型节日
- LunarDate.cn_week属性计算错误
- festival2中文档与代码不一致 HOT 1
- [新版本]Borax 4.1.0 HOT 1
- Typing Hints优化
- Festival初始化freq支持字符串monthly/yearly
- Logic Error for serials
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from borax.