GitHub - fatpo/python-lunardate: 纯python写的农历工具包,日期转换、闰月、大小月... · GitHub
Skip to content

fatpo/python-lunardate

 
 

Folders and files

Repository files navigation

A Chinese Calendar Library in Pure Python

fork lidaobing的项目

因为项目需要,需要获取当前日期所在月是农历大小月的标志,就在返回值中加入了isBig ...

用法没差,只是

from lunardate import LunarDate

print LunarDate.fromSolarDate(1976, 10 ,1)

返回值从:LunarDate(1976, 8, 8, 1) 变成 LunarDate(1976, 8, 8, 1, 0) ...


https://travis-ci.org/lidaobing/python-lunardate.png?branch=master:target:https://travis-ci.org/lidaobing/python-lunardate

Chinese Calendar: http://en.wikipedia.org/wiki/Chinese_calendar

Usage

>>> LunarDate.fromSolarDate(1976, 10, 1)
LunarDate(1976, 8, 8, 1)
>>> LunarDate(1976, 8, 8, 1).toSolarDate()
datetime.date(1976, 10, 1)
>>> LunarDate(1976, 8, 8, 1).year
1976
>>> LunarDate(1976, 8, 8, 1).month
8
>>> LunarDate(1976, 8, 8, 1).day
8
>>> LunarDate(1976, 8, 8, 1).isLeapMonth
True
>>> today = LunarDate.today()
>>> type(today).__name__
'LunarDate'
>>> # support '+' and '-' between datetime.date and datetime.timedelta
>>> ld = LunarDate(1976,8,8)
>>> sd = datetime.date(2008,1,1)
>>> td = datetime.timedelta(days=10)
>>> ld-ld
datetime.timedelta(0)
>>> ld-sd
datetime.timedelta(-11444)
>>> ld-td
LunarDate(1976, 7, 27, 0)
>>> sd-ld
datetime.timedelta(11444)
>>> ld+td
LunarDate(1976, 8, 18, 0)
>>> td+ld
LunarDate(1976, 8, 18, 0)
>>> ld2 = LunarDate.today()
>>> ld < ld2
True
>>> ld <= ld2
True
>>> ld > ld2
False
>>> ld >= ld2
False
>>> ld == ld2
False
>>> ld != ld2
True
>>> ld == ld
True
>>> LunarDate.today() == LunarDate.today()
True

News

  • 0.1.5: fix bug in ==
  • 0.1.4: support '+', '-' and compare, fix bug in year 2050
  • 0.1.3: support python 3.0

Limits

this library can only deal with year from 1900 to 2049 (in chinese calendar).

See also

About

纯python写的农历工具包,日期转换、闰月、大小月...

Topics

Resources

Stars

Watchers

Forks

Packages

Contributors

Languages

  • Python 100.0%