/// <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); }
/// <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)); } }
/// <summary> /// 通过阳历日期初始化 /// </summary> /// <param name="date">阳历日期</param> public Lunar(DateTime date) { solar = new Solar(date); int y = solar.getYear(); int m = solar.getMonth(); int d = solar.getDay(); int startYear, startMonth, startDay; int lunarYear, lunarMonth, lunarDay; if (y < 2000) { startYear = SolarUtil.BASE_YEAR; startMonth = SolarUtil.BASE_MONTH; startDay = SolarUtil.BASE_DAY; lunarYear = LunarUtil.BASE_YEAR; lunarMonth = LunarUtil.BASE_MONTH; lunarDay = LunarUtil.BASE_DAY; } else { startYear = SolarUtil.BASE_YEAR + 99; startMonth = 1; startDay = 1; lunarYear = LunarUtil.BASE_YEAR + 99; lunarMonth = 11; lunarDay = 25; } int diff = 0; for (int i = startYear; i < y; i++) { diff += 365; if (SolarUtil.isLeapYear(i)) { diff += 1; } } for (int i = startMonth; i < m; i++) { diff += SolarUtil.getDaysOfMonth(y, i); } diff += d - startDay; lunarDay += diff; int lastDate = LunarUtil.getDaysOfMonth(lunarYear, lunarMonth); while (lunarDay > lastDate) { lunarDay -= lastDate; lunarMonth = LunarUtil.nextMonth(lunarYear, lunarMonth); if (lunarMonth == 1) { lunarYear++; } lastDate = LunarUtil.getDaysOfMonth(lunarYear, lunarMonth); } year = lunarYear; month = lunarMonth; day = lunarDay; hour = solar.getHour(); minute = solar.getMinute(); second = solar.getSecond(); dayOffset = LunarUtil.computeAddDays(year, month, day); compute(); }