コード例 #1
0
ファイル: CalenderClass.cs プロジェクト: noobhacker/SuanMing
        public static Lunar SolarToLunar(Solar solar)
        {
            var lunar   = new Lunar();
            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;
            lunar.lunarMonth = lunarM;
            lunar.isleap     = false;
            if (leap != 0 && lunarM > leap)
            {
                lunar.lunarMonth = lunarM - 1;
                if (lunarM == leap + 1)
                {
                    lunar.isleap = true;
                }
            }

            lunar.lunarDay = lunarD;
            return(lunar);
        }
コード例 #2
0
ファイル: CalenderClass.cs プロジェクト: noobhacker/SuanMing
        public static 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;
            var  solar = new Solar();

            solar.solarYear  = (int)y;
            solar.solarMonth = (int)mm;
            solar.solarDay   = (int)dd;
            return(solar);
        }