Exemple #1
0
        public string getShenGong()
        {
            int monthZhiIndex = 0;
            int timeZhiIndex  = 0;

            for (int i = 0, j = MONTH_ZHI.Length; i < j; i++)
            {
                string zhi = MONTH_ZHI[i];
                if (lunar.getMonthZhiExact().Equals(zhi))
                {
                    monthZhiIndex = i;
                }
                if (lunar.getTimeZhi().Equals(zhi))
                {
                    timeZhiIndex = i;
                }
            }
            int zhiIndex   = (2 + (monthZhiIndex + timeZhiIndex)) % 12;
            int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);

            if (jiaZiIndex >= 60)
            {
                jiaZiIndex -= 60;
            }
            if (jiaZiIndex < 0)
            {
                jiaZiIndex += 60;
            }
            return(LunarUtil.JIA_ZI[jiaZiIndex]);
        }
Exemple #2
0
        /// <summary>
        /// 获取干支
        /// </summary>
        /// <returns>干支</returns>
        public string getGanZhi()
        {
            int offset = LunarUtil.getJiaZiIndex(lunar.getJieQiTable()["立春"].getLunar().getYearInGanZhiExact()) + this.index;

            if (daYun.getIndex() > 0)
            {
                offset += daYun.getStartAge() - 1;
            }
            offset %= LunarUtil.JIA_ZI.Length;
            return(LunarUtil.JIA_ZI[offset]);
        }
Exemple #3
0
        /// <summary>
        /// 获取干支
        /// </summary>
        /// <returns>干支</returns>
        public string getGanZhi()
        {
            int offset = LunarUtil.getJiaZiIndex(lunar.getTimeInGanZhi());
            int add    = this.index + 1;

            if (daYun.getIndex() > 0)
            {
                add += daYun.getStartAge() - 1;
            }
            offset += forward ? add : -add;
            int size = LunarUtil.JIA_ZI.Length;

            while (offset < 0)
            {
                offset += size;
            }
            offset %= size;
            return(LunarUtil.JIA_ZI[offset]);
        }
Exemple #4
0
        /// <summary>
        /// 获取干支
        /// </summary>
        /// <returns>干支</returns>
        public string getGanZhi()
        {
            if (index < 1)
            {
                return("");
            }
            int offset = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact());

            offset += yun.isForward() ? index : -index;
            int size = LunarUtil.JIA_ZI.Length;

            if (offset >= size)
            {
                offset -= size;
            }
            if (offset < 0)
            {
                offset += size;
            }
            return(LunarUtil.JIA_ZI[offset]);
        }
Exemple #5
0
        /// <summary>
        /// 通过八字获取阳历列表
        /// </summary>
        /// <param name="yearGanZhi">年柱</param>
        /// <param name="monthGanZhi">月柱</param>
        /// <param name="dayGanZhi">日柱</param>
        /// <param name="timeGanZhi">时柱</param>
        /// <returns>符合的阳历列表</returns>
        public static List <Solar> fromBaZi(string yearGanZhi, string monthGanZhi, string dayGanZhi, string timeGanZhi)
        {
            List <Solar> l          = new List <Solar>();
            Solar        today      = new Solar();
            Lunar        lunar      = today.getLunar();
            int          offsetYear = LunarUtil.getJiaZiIndex(lunar.getYearInGanZhiExact()) - LunarUtil.getJiaZiIndex(yearGanZhi);

            if (offsetYear < 0)
            {
                offsetYear = offsetYear + 60;
            }
            int    startYear = today.getYear() - offsetYear;
            int    hour      = 0;
            string timeZhi   = timeGanZhi.Substring(1);

            for (int i = 0, j = LunarUtil.ZHI.Length; i < j; i++)
            {
                if (LunarUtil.ZHI[i].Equals(timeZhi))
                {
                    hour = (i - 1) * 2;
                }
            }
            while (startYear >= SolarUtil.BASE_YEAR - 1)
            {
                int  year    = startYear - 1;
                int  counter = 0;
                int  month   = 12;
                int  day;
                bool found = false;
                while (counter < 15)
                {
                    if (year >= SolarUtil.BASE_YEAR)
                    {
                        day = 1;
                        if (year == SolarUtil.BASE_YEAR && month == SolarUtil.BASE_MONTH)
                        {
                            day = SolarUtil.BASE_DAY;
                        }
                        Solar solar = Solar.fromYmdHms(year, month, day, hour, 0, 0);
                        lunar = solar.getLunar();
                        if (lunar.getYearInGanZhiExact().Equals(yearGanZhi) && lunar.getMonthInGanZhiExact().Equals(monthGanZhi))
                        {
                            found = true;
                            break;
                        }
                    }
                    month++;
                    if (month > 12)
                    {
                        month = 1;
                        year++;
                    }
                    counter++;
                }
                if (found)
                {
                    counter = 0;
                    month--;
                    if (month < 1)
                    {
                        month = 12;
                        year--;
                    }
                    day = 1;
                    if (year == SolarUtil.BASE_YEAR && month == SolarUtil.BASE_MONTH)
                    {
                        day = SolarUtil.BASE_DAY;
                    }
                    Solar solar = Solar.fromYmdHms(year, month, day, hour, 0, 0);
                    while (counter < 61)
                    {
                        lunar = solar.getLunar();
                        if (lunar.getYearInGanZhiExact().Equals(yearGanZhi) && lunar.getMonthInGanZhiExact().Equals(monthGanZhi) && lunar.getDayInGanZhiExact().Equals(dayGanZhi) && lunar.getTimeInGanZhi().Equals(timeGanZhi))
                        {
                            l.Add(solar);
                            break;
                        }
                        solar = solar.next(1);
                        counter++;
                    }
                }
                startYear -= 60;
            }
            return(l);
        }