Code Monkey home page Code Monkey logo

Comments (2)

fastpx2014 avatar fastpx2014 commented on September 22, 2024 2
  1. borax 可以解决 根据阳历(公历)生日计算在今天阴历(农历)生日 ,使用 LunarFestival 类即可
  2. 在现实生活中,有的只过一个生日,有的有过两个生日,都存在。
  3. 在编程实现中,可以也返回闰月的那个生日,毕竟同一个闰月出现比较少,最近闰四月是在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.

allinu avatar allinu commented on September 22, 2024

收到,谢谢 @fastpx2014 🙏 🌹

from borax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.