Skip to content

Instantly share code, notes, and snippets.

@Lonenso
Created October 7, 2022 02:02
Show Gist options
  • Save Lonenso/662e8bb40f07b024d2bcbdc4347b96ab to your computer and use it in GitHub Desktop.
Save Lonenso/662e8bb40f07b024d2bcbdc4347b96ab to your computer and use it in GitHub Desktop.
from zhdate import ZhDate
from datetime import datetime
def nextYear(date):
date = datetime(date.year + 1, date.month, date.day)
zhDate = ZhDate.from_datetime(date)
return date, zhDate
def matched(date, zhDate, orignalDate, originalZhDate):
month = date.month == orignalDate.month and zhDate.lunar_month == originalZhDate.lunar_month
day = date.day == originalDate.day and zhDate.lunar_day == originalZhDate.lunar_day
return month and day
while True:
dateStr = input("please input date(1900-01-01):")
date = datetime.strptime(dateStr, "%Y-%m-%d")
zhDate = ZhDate.from_datetime(date)
originalDate = date
originalZhDate = zhDate
print(originalDate.date(), originalZhDate)
i = 0
while i < 100:
date, zhDate = nextYear(date)
if matched(date, zhDate, originalDate, originalZhDate):
print(date.date(), zhDate)
i += 1
@Lonenso
Copy link
Author

Lonenso commented Oct 7, 2022

requirements:
pip install zhdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment