Ejemplo n.º 1
0
        /// <summary>
        /// get the next jieqi on or after a specific date
        /// </summary>
        /// <param name="startDate">start date on Beijing Time</param>
        /// <returns></returns>
        public static CJieqi GetNextJieqi(DateTime startDate)
        {
            double d0         = DateTimeUtil.DateTimeToJulian(startDate.AddHours(-1 * BEJING_TIME_ZONE));
            double longitude0 = Earth.EclipticLongitude(d0);
            int    nextJieqi  = (int)Math.Floor(longitude0 / 15) + 1;
            int    nextDegree = nextJieqi * 15;

            DateTime nextJieqiTime = Earth.GetEclipticLongitudeTime(startDate, nextDegree);

            return(new CJieqi(nextJieqi % 24, nextJieqiTime.AddHours(BEJING_TIME_ZONE)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate Chinese New Year, see http://www.math.nus.edu.sg/aslaksen/calendar/chinese.shtml
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static DateTime GetChineseNewYear(int year)
        {
            //first give the December solstice time
            DateTime temp0 = new DateTime(year - 1, 12, 15);
            DateTime temp1 = Earth.GetEclipticLongitudeTime(temp0, 90);

            DateTime sui0 = GetBeijingTime(temp1); //this is the begig of sui

            temp0 = new DateTime(year, 12, 15);
            temp1 = Earth.GetEclipticLongitudeTime(temp0, 90);

            DateTime sui1 = GetBeijingTime(temp1); //this is the begin of next sui

            ArrayList monthes = new ArrayList();   //hold the start of each months during this sui

            //apply the rule #4, find the number of new Moon in a sui
            temp0 = MoonPhases.TruePhase(sui0, MPhase.New); //next new Moon time
            temp0 = GetBeijingTime(temp0);
            monthes.Add(temp0);
            int newYearMonth = 1; //for normal year, New Year would be the second monthes

            if (temp0 == sui0)    //new moon at the same date as begining of sui, it is 11 month
            {
                newYearMonth = 2;
            }

            while (temp0 < sui1)
            {
                temp1 = MoonPhases.TruePhase(temp0.AddDays(28), MPhase.New); //next new Moon time
                temp1 = GetBeijingTime(temp1);
                if (temp1 < sui1)
                {
                    monthes.Add(temp1);
                    temp0 = temp1;
                }
                else
                {
                    break;
                }
            }

            if (monthes.Count == 13 && newYearMonth == 1) //leap sui
            {
                //apply rule #5, see if the month 11 or 12th is leap month;
                temp0 = Earth.GetEclipticLongitudeTime((DateTime)monthes[0], 105);
                temp0 = GetBeijingTime(temp0);
                if (temp0 > (DateTime)monthes[1]) //first monthes is leap month
                {
                    newYearMonth = 2;
                }
                else
                {
                    //apply rule #5, see if the month 11 or 12th is leap month;
                    temp0 = Earth.GetEclipticLongitudeTime((DateTime)monthes[1], 120);
                    temp0 = GetBeijingTime(temp0);
                    if (temp0 > (DateTime)monthes[2]) //second monthes is leap month
                    {
                        newYearMonth = 2;
                    }
                }
            }

            return((DateTime)monthes[newYearMonth]);
        }