首页 > 编程 > Python > 正文

python实现的阳历转阴历(农历)算法

2020-02-23 05:20:00
字体:
来源:转载
供稿:网友


搜索了好几个python实现的万年历多有部分时间有问题,好多是来自这个代码:

代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Usage:  ccal Month [4-Digit-Year]
   or:  ccal 4-Digit-Year Month

This Python script is to show Solar and Lunar calender at the
same time. You need to have Python (2.0 or above) installed.

Acceptable date range:  1900/2 -- 2049/12

Output contains Chinese characters (mainland GB2312 encoding),
must be viewed in a Chinese-enabled system or "cxterm" etc.
programms under UNIX X-Windows.

The major reference for me to compose this program is:
lunar-2.1.tgz (1992), composed by
    Fung F. Lee <lee@umunhum.stanford.edu> and
    Ricky Yeung  <Ricky.Yeung@Eng.Sun.Com> .

And Lee and Yeung refered to:
    1. "Zhong1guo2 yin1yang2 ri4yue4 dui4zhao4 wan4nian2li4"
 by Lin2 Qi3yuan2. 《中国阴阳日月对照万年历》.林
    2. "Ming4li3 ge2xin1 zi3ping2 cui4yan2" by Xu2 Le4wu2.
 《命理革新子平粹言》.徐
    3.  Da1zhong4 wan4nian2li4. 《大众万年历》

License:
    GNU General Public License (GPL, see http://www.gnu.org).
    In short, users are free to use and distribute this program
    in whole. If users make revisions and distribute the revised
    one, they are required to keep the revised source accessible
    to the public.

Version:
    0.3.2,  Jan/16/2007, according to sprite's information, changed 3 codes:
            1954: 0x0a5d0 --> 0x0a5b0, 1956: 0x052d0 --> 0x052b0
            1916: 0x0d6a0 --> 0x056a0
    0.3.1,  Jan/15/2007, changed 1978's code from 0xb5a0 to 0xb6a0.
            A young lady's birth day (lunar 1978/8/4) problem reported
            on internet -- informed by sprite at linuxsir.org
    0.3.0,  Sep/25/2006, add coding line, prevent python to report warning
    0.2.0,  Jan/6/2002, ShengXiao(生肖), lunar leap month(闰月)
            added.
    0.1.0,  Jan/4/2002

 --- Changsen Xu <xucs007@yahoo.com>
'''

#Remember, in this program:
#   month=0 means Januaray, month=1 means February ...;
#   day=0 means the first day of a month, day=1 means the second day,
#       so as to ease manipulation of Python lists.
#   year=0 is 1900, until the last step to output

daysInSolarMonth= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表