iOS 开垦中阳历与公历的改变、星座总括

日期:2019-10-06编辑作者:星座

.h文件

探究了有个别个python实现的万年历多有一点时光至极,好多是来源于这些代码:


复制代码 代码如下:

#import <Foundation/Foundation.h>

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

@interface Lunar : NSObject

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

@property(assign) BOOL isleap;

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 <[email protected]> and
    Ricky Yeung  <[email protected]> .

@property(assign) int lunarDay;

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 ).
    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.

@property(assign) int lunarMonth;

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 <[email protected]>
'''

@property(assign) int lunarYear;

#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

@end

daysInSolarMonth= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
lunarMonthDays  = [29,30] # a short (long) lunar month has 29 (30) days */

@interface Solar : NSObject

shengXiaoEn     = ["Mouse", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
                   "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
shengXiaoGB     = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡",
                   "狗", "猪"]
zhiGB           = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉",
                   "戌", "亥"]
ganGB           = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]

/***公历 日*/

monthEn         = ['January', 'February', 'March', 'April', 'May', 'June',
                   'July', 'August', 'September', 'October', 'November',
                   'December']
weekdayEn       = ["Monday", "Tuesday", "Wednesday", "Thursday",
                   "Friday", "Saturday", "Sunday"]
weekdayGB       = ["一", "二", "三", "四", "五", "六", "日"]
numGB           = ['○', "一", "二", "三", "四", "五", "六", "七", "八", "九",
                   "十"]
lunarHoliday    = {'0_0':'春节', '4_4':'端午', '7_14':'中秋', '8_8':'重阳',
                   '0_14':'元宵'}

@property(assign) int solarDay;

#   encoding:
#        b bbbbbbbbbbbb bbbb
#      bit#     1 111111000000 0000
#               6 543210987654 3210
#     . ............ ....
#      month#   000000000111
#               M 123456789012   L
#          
#   b_j = 1 for long month, b_j = 0 for short month
#   L is the leap month of the year if 1<=L<=12; NO leap month if L = 0.
#   The leap month (if exists) is long one if M = 1.
yearCode = [
         0x04bd8, # 1900
    0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, # 1905
    0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, # 1910
    0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, # 1915
    0x056a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, # 1920
    0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, # 1925
    0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, # 1930
    0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, # 1935
    0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, # 1940
    0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, # 1945
    0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, # 1950
    0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, # 1955
    0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, # 1960
    0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, # 1965
    0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, # 1970
    0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, # 1975
    0x0d558, 0x0b540, 0x0b6a0, 0x195a6, 0x095b0, # 1980
    0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, # 1985
    0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, # 1990
    0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, # 1995
    0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, # 2000
    0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, # 2005
    0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, # 2010
    0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, # 2015
    0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, # 2020
    0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, # 2025
    0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, # 2030
    0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, # 2035
    0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, # 2040
    0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, # 2045
    0x0aa50, 0x1b255, 0x06d20, 0x0ada0   # 2049
]
yearsCoded = len(yearCode)

/***公历 月*/

from sys import argv, exit, stdout
from time import time, localtime
ow=stdout.write

@property(assign) int solarMonth;

 

/***公历 年*/

class LunarYearInfo:
    def __init__(self):
        self.yearDays = 0
        self.monthDays = [0]*13
        self.leapMonth = -1  # -1 means no lunar leap month

@property(assign) int solarYear;

yearInfo = [0]*yearsCoded #global variable
for i in range(yearsCoded):
    yearInfo[i] = LunarYearInfo()

@end

 

@interface LunarSolarConverter : NSObject

class Date:
    def __init__(self, year, month, day, weekday=-1, gan=-1, zhi=-1):
        self.year   =year
        self.month  =month
        self.day    =day
        self.weekday=weekday
        self.gan    =gan
        self.zhi    =zhi

/***公历转阳历*/

solar1st = Date(0, 0, 30, weekday=2)   #Wednesday, January 31, 1900
lunar1st = Date(0, 0, 0,  weekday=2, gan=6, zhi=0)
#Wednesday, First day, First month, 1900, 庚子年

+ (Solar *)lunarToSolar:(Lunar *)lunar;

 

/***农历转阳历*/

def error(msg):
    print 'Error:', msg; exit(0)

+ (Lunar *)solarToLunar:(Solar *)solar;

 

@end

def isSolarLeapYear (year):
    year=year+1900
    return (year%4 == 0) and (year%100 != 0) or (year%400 == 0)

.m文件

 


baseYear=1201 - 1900
# in fact, real baseYear=1201.  In order to ease calculation of
# leap years. real baseYear must conform to:
#   realBaseYear%4==1 and realBaseYear%400==1.
# Assert realBaseYear < solar1st.year .

//  LunarSolarConverter.m

# Compute the number of days from the Solar First Date
# month=0 means January, ...
def solarDaysFromBaseYear(d):    #d is a Date class
    delta = d.year - baseYear
    offset = delta*365 + delta/4 - delta/100 + delta/400
    for i in range(d.month):
     offset += daysInSolarMonth[i];
    if d.month>1 and isSolarLeapYear(d.year):
 offset += 1
    offset += d.day
##   print '___', year, month, day, 'offset=', offset ########
    return offset

#import "LunarSolarConverter.h"

# Compute the number of days from the Solar First Date
# month=0 means January, ..., year=0 means 1900, ...
def solarDaysFromFirstDate (d): #d is a Date class
    return solarDaysFromBaseYear (d) - solarDaysFromBaseYear (solar1st)

static int lunar_month_days[] =

 

{

def calcLunarDaysPerMonth(iYear):
    code = yearCode[iYear]
    leapMonth = code&0xf #leapMonth==0 means no lunar leap month

1887, 0x1694, 0x16aa, 0x4ad5, 0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a,

    code >>= 4
    for iMonth in range(12):
        yearInfo[iYear].monthDays[11-iMonth] = lunarMonthDays [code&0x1]
        code >>= 1

0x1d2a, 0xd54, 0x75aa, 0x156a, 0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a, 0x8d55, 0xad4, 0x135a, 0x495d,

    if leapMonth>0:
        yearInfo[iYear].leapMonth = leapMonth-1
        yearInfo[iYear].monthDays.insert (leapMonth,
                lunarMonthDays [code & 0x1])  

0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5, 0x16a8, 0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a,

def calcAllLunarYearsInfo():
    for iYear in range(yearsCoded):
        calcLunarDaysPerMonth (iYear)
        for iMonth in range(13):
     yearInfo[iYear].yearDays += yearInfo[iYear].monthDays[iMonth]

0xda8, 0x95b5, 0x56c, 0x12ae, 0x492f, 0x92e, 0xcc96, 0x1a94, 0x1d4a, 0xada9, 0xb5a, 0x56c, 0x726e, 0x125c,

 

0xf92d, 0x192a, 0x1a94, 0xdb4a, 0x16aa, 0xad4, 0x955b, 0x4ba, 0x125a, 0x592b, 0x152a, 0xf695, 0xd94, 0x16aa,

#input dateSolar, return (dateLunar, isLunarMonthOrNot)
def solar2Lunar(d): #d is a Date class
    dLunar = Date(-1, -1, -1) #unknown lunar Date class

0xaab5, 0x9b4, 0x14b6, 0x6a57, 0xa56, 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c, 0x94ae, 0x14ae, 0xa4c,

    offset = solarDaysFromFirstDate(d)

0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da, 0xa95d, 0x95a, 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4,

    dLunar.weekday  = (offset + solar1st.weekday)%7

0xd2da, 0x12b6, 0x936, 0x9497, 0x1496, 0x1564b, 0xd4a, 0xda8, 0xd5b4, 0x156c, 0x12ae, 0xa92f, 0x92e, 0xc96,

    for iYear in range(yearsCoded):
        if offset < yearInfo[iYear].yearDays:
            dLunar.year = iYear; break
 offset -= yearInfo[iYear].yearDays
    if dLunar.year == -1:   error ("Date out of range.")

0x6d4a, 0x1d4a, 0x10d65, 0xb58, 0x156c, 0xb26d, 0x125c, 0x192c, 0x9a95, 0x1a94, 0x1b4a, 0x4b55, 0xad4,

    dLunar.gan      = (dLunar.year + lunar1st.gan) % 10
    dLunar.zhi      = (dLunar.year + lunar1st.zhi) % 12

0xf55b, 0x4ba, 0x125a, 0xb92b, 0x152a, 0x1694, 0x96aa, 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57, 0xa56, 0x1526,

    for iMonth in range(13):
        if offset< yearInfo[dLunar.year].monthDays[iMonth]:
            dLunar.month = iMonth; break
 offset -= yearInfo[dLunar.year].monthDays[iMonth]

0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c, 0x1a4c, 0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d,

    dLunar.day = offset

0x95a, 0x149a, 0xda4b, 0x1a4a, 0x1aa4, 0xbb54, 0x16b4, 0xada, 0x495b, 0x936, 0xf497, 0x1496, 0x154a, 0xb6a5,

    isLeapMonth=0
    if yearInfo[dLunar.year].leapMonth >=0:
        if dLunar.month ==  yearInfo[iYear].leapMonth + 1:
            isLeapMonth=1
        if dLunar.month > yearInfo[dLunar.year].leapMonth:
            dLunar.month -= 1

0xda4, 0x15b4, 0x6ab6, 0x126e, 0x1092f, 0x92e, 0xc96, 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c, 0x125c, 0x792e,

    return (dLunar, isLeapMonth)

0x192c, 0xfa95, 0x1a94, 0x1b4a, 0xab55, 0xad4, 0x14da, 0x8a5d, 0xa5a, 0x1152b, 0x152a, 0x1694, 0xd6aa,

 

0x15aa, 0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53, 0xd54, 0x15aa, 0xa9b5, 0x96c, 0x14ae, 0x8a4e,

def getSolarDaysInMonth (year, month):
    if isSolarLeapYear(year) and month==1:
            return 29
    else:   return daysInSolarMonth[month]

0x1a4c, 0x11d26, 0x1aa4, 0x1b54, 0xcd6a, 0xada, 0x95c, 0x949d, 0x149a, 0x1a2a, 0x5b25, 0x1aa4, 0xfb52,

def num2GB (num):
    if num==10:
        return '十'
    elif num>10 and num<20:
        return '十' + numGB[num-10]

0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a, 0x136a5, 0xda4, 0x15ac

    tmp=''
    while num>10:
        tmp = numGB[num%10] + tmp
        num = int(num/10)
    tmp = numGB[num] + tmp
    return tmp

};

def lunarDate2GB (dLunar, isLeapMonth):
    tmp = str(dLunar.month)+'_'+str(dLunar.day)
    if lunarHoliday.has_key( tmp ):
        return ' [0;33;44m%s [0m  '% lunarHoliday[tmp] +
               ' '*(6-len(lunarHoliday[tmp]))
    elif dLunar.day==0:   
        tmp2 = '闰'*isLeapMonth + num2GB(dLunar.month+1) +'月'
        return ' [7m%s [0m' % tmp2 + ' '*(8-len(tmp2))
    elif dLunar.day<10:
        return '初' + num2GB(dLunar.day+1)
    else:
        return num2GB(dLunar.day+1)

static int solar_1_1[] =

def outputCalendar(year, month):
    dLunar = Date(-1,-1,-1)
    ow ('n     阳历%d年%d月         ' % (year+1900, month+1) )

{

    for iDay in range( getSolarDaysInMonth(year, month) ):
        dSolar = Date(year, month, iDay)
        dLunar, isLeapMonth = solar2Lunar (dSolar)

1887, 0xec04c, 0xec23f, 0xec435, 0xec649, 0xec83e, 0xeca51, 0xecc46, 0xece3a,

        if iDay==0:
            ow ('始于 阴历%s年%s%s月 (%s%s年, 生肖属%s)n' %
                ( num2GB(dLunar.year+1900), '闰'*isLeapMonth,
                  num2GB(dLunar.month+1),
                  ganGB [dLunar.gan], zhiGB[dLunar.zhi], shengXiaoGB[dLunar.zhi]
                ))
            ow ('='*74 + 'n')
            for i in range(7):
                ow ("%3s %2s     " % (weekdayEn[i][:3], weekdayGB[i]) )
            ow('nn')
            for i in range(dLunar.weekday): ow(' '*11)

0xed04d, 0xed242, 0xed436, 0xed64a, 0xed83f, 0xeda53, 0xedc48, 0xede3d, 0xee050, 0xee244, 0xee439, 0xee64d,

        elif dLunar.weekday==0: ow('n')

0xee842, 0xeea36, 0xeec4a, 0xeee3e, 0xef052, 0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b, 0xefe41,

        ow ( "%2d %-8s" %(iDay+1, lunarDate2GB(dLunar, isLeapMonth) ) )
    ow('nn')

0xf0054, 0xf0248, 0xf043c, 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d, 0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651,

 

0xf1846, 0xf1a3a, 0xf1c4e, 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848, 0xf2a3b, 0xf2c4f, 0xf2e45,

def checkArgv (argv):
    argc = len(argv)
    if argc==1 or argv[1] in ('-h', '--help'):
        print __doc__; exit(0)

0xf3039, 0xf324d, 0xf3442, 0xf3636, 0xf384a, 0xf3a3d, 0xf3c51, 0xf3e46, 0xf403b, 0xf424e, 0xf4443, 0xf4638,

    #in case people input arguments as "4-digit-year month"
    if argc==3 and len(argv[1]) == 4 and len(argv[2]) in (1,2):
        argv[1], argv[2] = argv[2], argv[1]

0xf484c, 0xf4a3f, 0xf4c52, 0xf4e48, 0xf503c, 0xf524f, 0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35, 0xf5e49,

   
    #Get month
    month=-1
    for iMonth in range(12):
        if argv[1].lower() == monthEn[iMonth].lower() or
           argv[1].lower() == monthEn[iMonth][:3].lower():
               month = iMonth+1; break
    if month==-1:
        month = eval(argv[1])

0xf603e, 0xf6251, 0xf6446, 0xf663b, 0xf684f, 0xf6a43, 0xf6c37, 0xf6e4b, 0xf703f, 0xf7252, 0xf7447, 0xf763c,

    if month<1 or month>12:     error ("Month not within 1--12.")

0xf7850, 0xf7a45, 0xf7c39, 0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46, 0xf8c3b, 0xf8e4f,

    #Get year
    if argc==2: year = localtime(time())[0]
    else:
        if len(argv[2]) != 4:   error ("Year must be 4 digits.")
        year = eval(argv[2])
        if year<1900 or year>= 1900+yearsCoded or (year==1900 and month==1):
            error ("Year must be within %d--%d, excluding 1900/1."
                    % (1900, 1900 + yearsCoded-1) )

0xf9044, 0xf9237, 0xf944a, 0xf963f, 0xf9853, 0xf9a47, 0xf9c3c, 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641,

    return year-1900, month-1

0xfa836, 0xfaa49, 0xfac3d, 0xfae52, 0xfb047, 0xfb23a, 0xfb44e, 0xfb643, 0xfb837, 0xfba4a, 0xfbc3f, 0xfbe53,

year, month = checkArgv(argv)
calcAllLunarYearsInfo()
outputCalendar(year, month)

0xfc048, 0xfc23c, 0xfc450, 0xfc645, 0xfc839, 0xfca4c, 0xfcc41, 0xfce36, 0xfd04a, 0xfd23d, 0xfd451, 0xfd646,

其一也是有标题(壹玖捌玖年九月的数目转变到农历就有毛病)

0xfd83a, 0xfda4d, 0xfdc43, 0xfde37, 0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44, 0xfee38,

看了一点个程序,开掘实现那个并无需什么NB的算法(好像也不设有这么的算法)能够直接落成农历转为农历的,都是记录了一群农历的数额,然后依照和骨干时间来算相差几天来计量的,全数农历数据的精确性决定了那一个程序的没有错。

0xff04c, 0xff241, 0xff436, 0xff64a, 0xff83e, 0xffa51, 0xffc46, 0xffe3a, 0x10004e, 0x100242, 0x100437,

校友给了八个lua的次第,作者试了一晃,还尚未找到错误的,先直接给上前后相继(直接从lua转成python的,写的可比乱)

0x10064b, 0x100841, 0x100a53, 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438, 0x10164c, 0x101842, 0x101a35,

复制代码 代码如下:

0x101c49, 0x101e3d, 0x102051, 0x102245, 0x10243a, 0x10264e, 0x102843, 0x102a37, 0x102c4b, 0x102e3f, 0x103053,

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math

0x103247, 0x10343b, 0x10364f, 0x103845, 0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249, 0x10443d, 0x104651,

def GetDayOf(st):
    #–天干名称
    cTianGan = ["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
    #–地支名称
    cDiZhi = ["子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"]
    #–属相名称
    cShuXiang = ["鼠","牛","虎","兔","龙","蛇", "马","羊","猴","鸡","狗","猪"]
    #–公历日期名
    cDayName =[
        "*","初一","初二","初三","初四","初五",
        "初六","初七","初八","初九","初十",
        "十一","十二","十三","十四","十五",
        "十六","十七","十八","十九","二十",
        "廿一","廿二","廿三","廿四","廿五",
        "廿六","廿七","廿八","廿九","三十"
    ]
    #–阳历月份名
    cMonName = ["*","正","二","三","四","五","六", "七","八","九","十","十一","腊"]

0x104846, 0x104a3a, 0x104c4e, 0x104e43, 0x105038, 0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f,

    #–阳历每月前边的命局
    wMonthAdd = [0,31,59,90,120,151,181,212,243,273,304,334]
    #– 农历数据
    wNongliData = [2635,333387,1701,1748,267701,694,2391,133423,1175,396438
    ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
    ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
    ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
    ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
    ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395
    ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031
    ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222
    ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709
    ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877]

0x105e45, 0x106039, 0x10624c, 0x106441, 0x106635, 0x106849, 0x106a3d, 0x106c51, 0x106e47, 0x10703c, 0x10724f,

    #—取当前阳历年、月、日—
    wCurYear = st["year"]
    wCurMonth = st["mon"]
    wCurDay = st["day"]
    #—总结到开端时间1921年5月8日的命局:一九二四-2-8(初春中一)—
    #nTheDate = (wCurYear – 1921) * 365 + (wCurYear – 1921)/4 + wCurDay + wMonthAdd[wCurMonth] – 38
    nTheDate = (wCurYear – 1921) * 365 + (wCurYear – 1921)/4 + wCurDay

0x107444, 0x107638, 0x10784c, 0x107a3f, 0x107c53, 0x107e48

  • wMonthAdd[wCurMonth-1] – 38
        if (((wCurYear % 4) == 0) and (wCurMonth > 2)):
            nTheDate = nTheDate + 1

};

    #–总计公历天干、地支、月、日—
    nIsEnd = 0
    m = 0
    while nIsEnd != 1:
        #if wNongliData[m+1] < 4095:
        if wNongliData[m] < 4095:
            k = 11
        else:
            k = 12
        n = k
        while n>=0:
彩世界,            nBit = wNongliData[m]
            for i in range(n):
                nBit = math.floor(nBit/2);

int GetBitInt(int data, int length, int shift) {

            nBit = nBit % 2

return (data & (((1 << length) - 1) << shift)) >> shift;

            if nTheDate <= (29 + nBit):
                nIsEnd = 1
                break

}

            nTheDate = nTheDate – 29 – nBit
            n = n – 1

//WARNING: Dates before Oct. 1582 are inaccurate

        if nIsEnd != 0:
            break
        m = m + 1

long SolarToInt(int y, int m, int d) {

    wCurYear = 1921 + m
    wCurMonth = k – n + 1
    wCurDay = int(math.floor(nTheDate))
    if k == 12:
        if wCurMonth == wNongliData[m] / 65536 + 1:
            wCurMonth = 1 – wCurMonth
        elif wCurMonth > wNongliData[m] / 65536 + 1:
            wCurMonth = wCurMonth – 1

m = (m + 9) % 12;

    print '阳历', st["year"], st["mon"], st["day"]
    print '农历', wCurYear, wCurMonth, wCurDay
    #–生成公历天干、地支、属相 ==> wNongli–
    szShuXiang = cShuXiang[(((wCurYear - 4) % 60) % 12) + 1]
    szShuXiang = cShuXiang[(((wCurYear - 4) % 60) % 12) + 1]
    zNongli = szShuXiang + '(' + cTianGan[(((wCurYear - 4) % 60) % 10)] + cDiZhi[(((wCurYear - 4) % 60) % 12)] + ')年'
    #–szNongli,"%s(%s%s)年",szShuXiang,cTianGan[((wCurYear - 4) % 60) % 10],cDiZhi[((wCurYear - 4) % 60) % 12]);

y = y - m / 10;

    #–生成阳历月、日 ==> wNongliDay–*/
    if wCurMonth < 1:
        szNongliDay =  "闰" + cMonName[(-1 * wCurMonth)]
    else:
        szNongliDay = cMonName[wCurMonth]

return 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 + (d - 1);

    szNongliDay =  szNongliDay + "月" + cDayName[wCurDay]
    print szNongliDay
    #return szNongli .. szNongliDay

}

def main():
    st = {"year": 1989, "mon": 8, "day": 1}
    GetDayOf(st)
    st1 = {"year": 2013, "mon": 10, "day": 7}
    GetDayOf(st1)
    st1 = {"year": 2013, "mon": 10, "day": 1}
    GetDayOf(st1)
    #print("" .. GetDayOf(st))
main()

@implementation Lunar : NSObject

数据差不离正确了,依据自身的内需改一改程序就能够了。今后一时光在改好一点的。

@end

复制代码 代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- '''...

@implementation Solar : NSObject

@end

@implementation LunarSolarConverter

+ (Solar *)SolarFromInt:(long)g

{

long y = (10000 * g + 14780) / 3652425;

long ddd = g - (365 * y + y / 4 - y / 100 + y / 400);

if (ddd < 0) {

y--;

ddd = g - (365 * y + y / 4 - y / 100 + y / 400);

}

long mi = (100 * ddd + 52) / 3060;

long mm = (mi + 2) % 12 + 1;

y = y + (mi + 2) / 12;

long dd = ddd - (mi * 306 + 5) / 10 + 1;

Solar *solar = [[Solar alloc] init];

solar.solarYear = (int) y;

solar.solarMonth = (int) mm;

solar.solarDay = (int) dd;

return solar;

}

+ (Solar *)lunarToSolar:(Lunar *)lunar;

{

int days = lunar_month_days[lunar.lunarYear - lunar_month_days[0]];

int leap = GetBitInt(days, 4, 13);

int offset = 0;

int loopend = leap;

if (!lunar.isleap) {

if (lunar.lunarMonth <= leap || leap == 0) {

loopend = lunar.lunarMonth - 1;

} else {

loopend = lunar.lunarMonth;

}

}

for (int i = 0; i < loopend; i++) {

offset += GetBitInt(days, 1, 12 - i) == 1 ? 30 : 29;

}

offset += lunar.lunarDay;

int solar11 = solar_1_1[lunar.lunarYear - solar_1_1[0]];

int y = GetBitInt(solar11, 12, 9);

int m = GetBitInt(solar11, 4, 5);

int d = GetBitInt(solar11, 5, 0);

return [self SolarFromInt:(SolarToInt(y, m, d) + offset - 1)];

}

+ (Lunar *)solarToLunar:(Solar *)solar;

{

Lunar *lunar = [[Lunar alloc] init];

int index = solar.solarYear - solar_1_1[0];

int data = (solar.solarYear << 9) | (solar.solarMonth << 5) | (solar.solarDay);

int solar11 = 0;

if (solar_1_1[index] > data) {

index--;

}

solar11 = solar_1_1[index];

int y = GetBitInt(solar11, 12, 9);

int m = GetBitInt(solar11, 4, 5);

int d = GetBitInt(solar11, 5, 0);

long offset = SolarToInt(solar.solarYear, solar.solarMonth, solar.solarDay) - SolarToInt(y, m, d);

int days = lunar_month_days[index];

int leap = GetBitInt(days, 4, 13);

int lunarY = index + solar_1_1[0];

int lunarM = 1;

int lunarD = 1;

offset += 1;

for (int i = 0; i < 13; i++) {

int dm = GetBitInt(days, 1, 12 - i) == 1 ? 30 : 29;

if (offset > dm) {

lunarM++;

offset -= dm;

} else {

break;

}

}

lunarD = (int) (offset);

lunar.lunarYear = lunarY;

本文由彩世界发布于星座,转载请注明出处:iOS 开垦中阳历与公历的改变、星座总括

关键词:

营业干货--关于PGC型内容类产品的运营

网络行当作过内容的都精通,有且唯有二种内容生产方式,PGC和UGC 写在前头的话 PGC:职业内容生产格局 为何要写三...

详细>>

月白风三夏知秋

壹 是日,细雨微濛,湖水泛漪,青山目远,心事稍歇。 那青衣男子,剑气如霜,蹙眉而舞,不苟言笑。 雨水和着水...

详细>>

【凯源】厨中校和店长的爱情遗闻 优酸乳吸管篇

今天厨师长和店长出门去采购了。 天气一凉下来,我们就发现店长和厨师长都解锁了新的习惯。 两人回来时,正是晚...

详细>>

天天学一些(09):年轻人爱吃哪一套?

彩世界,星座、情侣、萌物、生肖、态度 年轻人的营销的关键要素。...

详细>>