예제 #1
0
        /// <summary>
        /// 获取本周的阳历日期列表(可能跨月)
        /// </summary>
        /// <returns>本周的阳历日期列表</returns>
        public List <Solar> getDays()
        {
            Solar        firstDay = getFirstDay();
            List <Solar> l        = new List <Solar>();

            l.Add(firstDay);
            for (int i = 1; i < 7; i++)
            {
                l.Add(firstDay.next(i));
            }
            return(l);
        }
예제 #2
0
        /// <summary>
        /// 获取本月的阳历日期列表
        /// </summary>
        /// <returns>阳历日期列表</returns>
        public List <Solar> getDays()
        {
            List <Solar> l = new List <Solar>(31);
            Solar        d = new Solar(year, month, 1);

            l.Add(d);
            int days = SolarUtil.getDaysOfMonth(year, month);

            for (int i = 1; i < days; i++)
            {
                l.Add(d.next(i));
            }
            return(l);
        }
예제 #3
0
 /// <summary>
 /// 周推移
 /// </summary>
 /// <param name="weeks">推移的周数,负数为倒推</param>
 /// <param name="separateMonth">是否按月单独计算</param>
 /// <returns>推移后的阳历周</returns>
 public SolarWeek next(int weeks, bool separateMonth)
 {
     if (0 == weeks)
     {
         return(new SolarWeek(year, month, day, start));
     }
     if (separateMonth)
     {
         int       n    = weeks;
         DateTime  c    = new DateTime(year, month, day);
         SolarWeek week = new SolarWeek(c, start);
         int       m    = this.month;
         bool      plus = n > 0;
         while (0 != n)
         {
             c    = c.AddDays(plus ? 7 : -7);
             week = new SolarWeek(c, start);
             int weekMonth = week.getMonth();
             if (m != weekMonth)
             {
                 int index = week.getIndex();
                 if (plus)
                 {
                     if (1 == index)
                     {
                         Solar firstDay = week.getFirstDay();
                         week      = new SolarWeek(firstDay.getYear(), firstDay.getMonth(), firstDay.getDay(), start);
                         weekMonth = week.getMonth();
                     }
                     else
                     {
                         c    = new DateTime(week.getYear(), week.getMonth(), 1);
                         week = new SolarWeek(c, start);
                     }
                 }
                 else
                 {
                     int size = SolarUtil.getWeeksOfMonth(week.getYear(), week.getMonth(), start);
                     if (size == index)
                     {
                         Solar firstDay = week.getFirstDay();
                         Solar lastDay  = firstDay.next(6);
                         week      = new SolarWeek(lastDay.getYear(), lastDay.getMonth(), lastDay.getDay(), start);
                         weekMonth = week.getMonth();
                     }
                     else
                     {
                         c    = new DateTime(week.getYear(), week.getMonth(), SolarUtil.getDaysOfMonth(week.getYear(), week.getMonth()));
                         week = new SolarWeek(c, start);
                     }
                 }
                 m = weekMonth;
             }
             n -= plus ? 1 : -1;
         }
         return(week);
     }
     else
     {
         DateTime c = new DateTime(year, month, day);
         c = c.AddDays(weeks * 7);
         return(new SolarWeek(c, start));
     }
 }
예제 #4
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);
        }