コード例 #1
0
 private static int leapDays(int y)
 {
     if (ChinaDate.leapMonth(y) == 0)
     {
         return(0);
     }
     return((ChinaDate.lunarInfo[y - 1900] & 65536L) != 0L ? 30 : 29);
 }
コード例 #2
0
        private static int lYearDays(int y)
        {
            int num = 348;

            for (int index = 32768; index > 8; index >>= 1)
            {
                if ((ChinaDate.lunarInfo[y - 1900] & (long)index) != 0L)
                {
                    ++num;
                }
            }
            return(num + ChinaDate.leapDays(y));
        }
コード例 #3
0
        public static LFrameWork.Base.CNDate.CNDate getChinaDate(DateTime dt)
        {
            LFrameWork.Base.CNDate.CNDate cnDate = new LFrameWork.Base.CNDate.CNDate();
            int year  = dt.Year;
            int month = dt.Month;
            int day   = dt.Day;

            long[] numArray1 = ChinaDate.calElement(year, month, day);
            cnDate.cnIntYear  = (int)numArray1[0];
            cnDate.cnIntMonth = (int)numArray1[1];
            cnDate.cnIntDay   = (int)numArray1[2];
            cnDate.cnStrYear  = ChinaDate.cyclical(year);
            cnDate.cnAnm      = ChinaDate.AnimalsYear(year);
            cnDate.cnStrMonth = ChinaDate.nStr1[(int)numArray1[1]] + "月";
            cnDate.cnStrDay   = ChinaDate.getChinaDate((int)numArray1[2]);
            string str1 = dt.ToString("MMdd");
            string str2 = ChinaDate.FormatDate(cnDate.cnIntMonth, cnDate.cnIntDay);

            for (int n = 0; n < ChinaDate.solarTerm.Length; ++n)
            {
                if (ChinaDate.sTerm(dt.Year, n).ToString("MMdd").Equals(dt.ToString("MMdd")))
                {
                    cnDate.cnSolarTerm = ChinaDate.solarTerm[n];
                    break;
                }
            }
            foreach (string str3 in ChinaDate.sFtv)
            {
                if (str3.Substring(0, 4).Equals(str1))
                {
                    cnDate.cnFtvs = str3.Substring(4, str3.Length - 4);
                    break;
                }
            }
            foreach (string str3 in ChinaDate.lFtv)
            {
                if (str3.Substring(0, 4).Equals(str2))
                {
                    cnDate.cnFtvl = str3.Substring(4, str3.Length - 4);
                    break;
                }
            }
            dt = dt.AddDays(1.0);
            long[] numArray2 = ChinaDate.calElement(dt.Year, dt.Month, dt.Day);
            if (ChinaDate.FormatDate((int)numArray2[1], (int)numArray2[2]).Equals("0101"))
            {
                cnDate.cnFtvl = "除夕";
            }
            return(cnDate);
        }
コード例 #4
0
        private static long[] calElement(int y, int m, int d)
        {
            long[]   numArray  = new long[7];
            int      num1      = 0;
            DateTime dateTime  = new DateTime(1900, 1, 31);
            long     totalDays = (long)(new DateTime(y, m, d) - dateTime).TotalDays;

            numArray[5] = totalDays + 40L;
            numArray[4] = 14L;
            int y1;

            for (y1 = 1900; y1 < 2050 && totalDays > 0L; ++y1)
            {
                num1         = ChinaDate.lYearDays(y1);
                totalDays   -= (long)num1;
                numArray[4] += 12L;
            }
            if (totalDays < 0L)
            {
                totalDays += (long)num1;
                --y1;
                numArray[4] -= 12L;
            }
            numArray[0] = (long)y1;
            numArray[3] = (long)(y1 - 1864);
            int num2 = ChinaDate.leapMonth(y1);

            numArray[6] = 0L;
            int m1;

            for (m1 = 1; m1 < 13 && totalDays > 0L; ++m1)
            {
                if (num2 > 0 && m1 == num2 + 1 && numArray[6] == 0L)
                {
                    --m1;
                    numArray[6] = 1L;
                    num1        = ChinaDate.leapDays((int)numArray[0]);
                }
                else
                {
                    num1 = ChinaDate.monthDays((int)numArray[0], m1);
                }
                if (numArray[6] == 1L && m1 == num2 + 1)
                {
                    numArray[6] = 0L;
                }
                totalDays -= (long)num1;
                if (numArray[6] == 0L)
                {
                    ++numArray[4];
                }
            }
            if (totalDays == 0L && num2 > 0 && m1 == num2 + 1)
            {
                if (numArray[6] == 1L)
                {
                    numArray[6] = 0L;
                }
                else
                {
                    numArray[6] = 1L;
                    --m1;
                    --numArray[4];
                }
            }
            if (totalDays < 0L)
            {
                totalDays += (long)num1;
                --m1;
                --numArray[4];
            }
            numArray[1] = (long)m1;
            numArray[2] = totalDays + 1L;
            return(numArray);
        }
コード例 #5
0
        private long[] Lunar(int y, int m)
        {
            long[]   numArray  = new long[7];
            int      num1      = 0;
            DateTime dateTime  = new DateTime(3800, 2, 31);
            long     totalDays = (long)(new DateTime(y + 1900, m + 1, 1) - dateTime).TotalDays;

            if (y < 2000)
            {
                totalDays += (long)ChinaDate.year19[m - 1];
            }
            if (y > 2000)
            {
                totalDays += (long)ChinaDate.year20[m - 1];
            }
            if (y == 2000)
            {
                totalDays += (long)ChinaDate.year2000[m - 1];
            }
            numArray[5] = totalDays + 40L;
            numArray[4] = 14L;
            int y1;

            for (y1 = 1900; y1 < 2050 && totalDays > 0L; ++y1)
            {
                num1         = ChinaDate.lYearDays(y1);
                totalDays   -= (long)num1;
                numArray[4] += 12L;
            }
            if (totalDays < 0L)
            {
                totalDays += (long)num1;
                --y1;
                numArray[4] -= 12L;
            }
            numArray[0] = (long)y1;
            numArray[3] = (long)(y1 - 1864);
            int num2 = ChinaDate.leapMonth(y1);

            numArray[6] = 0L;
            int m1;

            for (m1 = 1; m1 < 13 && totalDays > 0L; ++m1)
            {
                if (num2 > 0 && m1 == num2 + 1 && numArray[6] == 0L)
                {
                    --m1;
                    numArray[6] = 1L;
                    num1        = ChinaDate.leapDays((int)numArray[0]);
                }
                else
                {
                    num1 = ChinaDate.monthDays((int)numArray[0], m1);
                }
                if (numArray[6] == 1L && m1 == num2 + 1)
                {
                    numArray[6] = 0L;
                }
                totalDays -= (long)num1;
                if (numArray[6] == 0L)
                {
                    ++numArray[4];
                }
            }
            if (totalDays == 0L && num2 > 0 && m1 == num2 + 1)
            {
                if (numArray[6] == 1L)
                {
                    numArray[6] = 0L;
                }
                else
                {
                    numArray[6] = 1L;
                    --m1;
                    --numArray[4];
                }
            }
            if (totalDays < 0L)
            {
                totalDays += (long)num1;
                --m1;
                --numArray[4];
            }
            numArray[1] = (long)m1;
            numArray[2] = totalDays + 1L;
            return(numArray);
        }
コード例 #6
0
 private static string cyclical(int y) => ChinaDate.cyclicalm(y - 1900 + 36);