mirror of
https://gitee.com/6tail/lunar-csharp.git
synced 2025-12-06 10:19:07 +08:00
南京大XX纪念日更改为国家公祭日;新增初候、二候、三候;新增三元九运;新增道历戊日;补充灶马头相关内容;修复九星错误;新增太岁方位;新增道历天赦日;修复八字转阳历的错误;修复SolarWeek获取当月第几周的错误。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# lunar [](https://github.com/6tail/lunar-csharp/blob/master/LICENSE)
|
||||
|
||||
lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。
|
||||
lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)、佛历和道历工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。
|
||||
|
||||
> 支持.NET 2.0及以上版本。
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using com.nlf.calendar.util;
|
||||
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
@@ -24,5 +25,58 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return fromYmdHms(date.Year, date.Month, date.Day, date.Hour, date.Minute,date.Second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a<EFBFBD><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bС<62><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a<EFBFBD><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="ay"><3E><>a</param>
|
||||
/// <param name="am"><3E><>a</param>
|
||||
/// <param name="ad"><3E><>a</param>
|
||||
/// <param name="by"><3E><>b</param>
|
||||
/// <param name="bm"><3E><>b</param>
|
||||
/// <param name="bd"><3E><>b</param>
|
||||
/// <returns></returns>
|
||||
public static int getDaysBetween(int ay, int am, int ad, int by, int bm, int bd)
|
||||
{
|
||||
int n;
|
||||
int days;
|
||||
int i;
|
||||
if (ay == by)
|
||||
{
|
||||
n = SolarUtil.getDaysInYear(by, bm, bd) - SolarUtil.getDaysInYear(ay, am, ad);
|
||||
}
|
||||
else if (ay > by)
|
||||
{
|
||||
days = SolarUtil.getDaysOfYear(by) - SolarUtil.getDaysInYear(by, bm, bd);
|
||||
for (i = by + 1; i < ay; i++)
|
||||
{
|
||||
days += SolarUtil.getDaysOfYear(i);
|
||||
}
|
||||
days += SolarUtil.getDaysInYear(ay, am, ad);
|
||||
n = -days;
|
||||
}
|
||||
else
|
||||
{
|
||||
days = SolarUtil.getDaysOfYear(ay) - SolarUtil.getDaysInYear(ay, am, ad);
|
||||
for (i = ay + 1; i < by; i++)
|
||||
{
|
||||
days += SolarUtil.getDaysOfYear(i);
|
||||
}
|
||||
days += SolarUtil.getDaysInYear(by, bm, bd);
|
||||
n = days;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a<EFBFBD><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bС<62><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a<EFBFBD><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="date0"><3E><><EFBFBD><EFBFBD>a</param>
|
||||
/// <param name="date1"><3E><><EFBFBD><EFBFBD>b</param>
|
||||
/// <returns><3E><><EFBFBD><EFBFBD></returns>
|
||||
public static int getDaysBetween(DateTime date0, DateTime date1)
|
||||
{
|
||||
return getDaysBetween(date0.Year, date0.Month, date0.Day, date1.Year, date1.Month, date1.Day);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
639
lunar/Lunar.cs
639
lunar/Lunar.cs
@@ -220,15 +220,15 @@ namespace com.nlf.calendar
|
||||
public Lunar(DateTime date)
|
||||
{
|
||||
solar = new Solar(date);
|
||||
DateTime c = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
int y = solar.getYear();
|
||||
LunarYear ly = LunarYear.fromYear(y);
|
||||
int currentYear = solar.getYear();
|
||||
int currentMonth = solar.getMonth();
|
||||
int currentDay = solar.getDay();
|
||||
LunarYear ly = LunarYear.fromYear(currentYear);
|
||||
foreach (LunarMonth m in ly.getMonths())
|
||||
{
|
||||
// 初一
|
||||
DateTime firstDay = Solar.fromJulianDay(m.getFirstJulianDay()).getCalendar();
|
||||
firstDay = ExactDate.fromYmd(firstDay.Year, firstDay.Month, firstDay.Day);
|
||||
int days = c.Subtract(firstDay).Days;
|
||||
Solar firstDay = Solar.fromJulianDay(m.getFirstJulianDay());
|
||||
int days = ExactDate.getDaysBetween(firstDay.getYear(), firstDay.getMonth(), firstDay.getDay(), currentYear, currentMonth, currentDay);
|
||||
if (days < m.getDayCount())
|
||||
{
|
||||
year = m.getYear();
|
||||
@@ -849,18 +849,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>节</returns>
|
||||
public string getJie()
|
||||
{
|
||||
string jie = "";
|
||||
for (int i = 0, j = JIE_QI_IN_USE.Length; i < j; i += 2)
|
||||
{
|
||||
string key = JIE_QI_IN_USE[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
jie = key;
|
||||
break;
|
||||
return convertJieQi(key);
|
||||
}
|
||||
}
|
||||
return convertJieQi(jie);
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -869,18 +867,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>气</returns>
|
||||
public string getQi()
|
||||
{
|
||||
string qi = "";
|
||||
for (int i = 1, j = JIE_QI_IN_USE.Length; i < j; i += 2)
|
||||
{
|
||||
string key = JIE_QI_IN_USE[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
qi = key;
|
||||
break;
|
||||
return convertJieQi(key);
|
||||
}
|
||||
}
|
||||
return convertJieQi(qi);
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1151,7 +1147,7 @@ namespace com.nlf.calendar
|
||||
/// <summary>
|
||||
/// 获取日福神方位描述
|
||||
/// </summary>
|
||||
/// <returns>福神方位描述,如东北</returns>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getDayPositionFuDesc()
|
||||
{
|
||||
return getDayPositionFuDesc(2);
|
||||
@@ -1161,7 +1157,7 @@ namespace com.nlf.calendar
|
||||
/// 获取日福神方位描述
|
||||
/// </summary>
|
||||
/// <param name="sect">流派,可选1或2</param>
|
||||
/// <returns>福神方位描述,如东北</returns>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getDayPositionFuDesc(int sect)
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getDayPositionFu(sect)];
|
||||
@@ -1170,7 +1166,7 @@ namespace com.nlf.calendar
|
||||
/// <summary>
|
||||
/// 获取日财神方位
|
||||
/// </summary>
|
||||
/// <returns>财神方位,如艮</returns>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getDayPositionCai()
|
||||
{
|
||||
return LunarUtil.POSITION_CAI[dayGanIndex + 1];
|
||||
@@ -1179,12 +1175,231 @@ namespace com.nlf.calendar
|
||||
/// <summary>
|
||||
/// 获取日财神方位描述
|
||||
/// </summary>
|
||||
/// <returns>财神方位描述,如东北</returns>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getDayPositionCaiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getDayPositionCai()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取年太岁方位
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算</param>
|
||||
/// <returns>方位</returns>
|
||||
public string getYearPositionTaiSui(int sect)
|
||||
{
|
||||
int yearZhiIndex;
|
||||
switch (sect)
|
||||
{
|
||||
case 1:
|
||||
yearZhiIndex = this.yearZhiIndex;
|
||||
break;
|
||||
case 3:
|
||||
yearZhiIndex = this.yearZhiIndexExact;
|
||||
break;
|
||||
default:
|
||||
yearZhiIndex = this.yearZhiIndexByLiChun;
|
||||
break;
|
||||
}
|
||||
return LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取年太岁方位(默认流派2新年以立春零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位</returns>
|
||||
public string getYearPositionTaiSui()
|
||||
{
|
||||
return getYearPositionTaiSui(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取年太岁方位描述
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算</param>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getYearPositionTaiSuiDesc(int sect)
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getYearPositionTaiSui(sect)];
|
||||
}
|
||||
|
||||
protected string getMonthPositionTaiSui(int monthZhiIndex, int monthGanIndex)
|
||||
{
|
||||
string p;
|
||||
int m = monthZhiIndex - LunarUtil.BASE_MONTH_ZHI_INDEX;
|
||||
if (m < 0)
|
||||
{
|
||||
m += 12;
|
||||
}
|
||||
switch (m)
|
||||
{
|
||||
case 0:
|
||||
case 4:
|
||||
case 8:
|
||||
p = "艮";
|
||||
break;
|
||||
case 2:
|
||||
case 6:
|
||||
case 10:
|
||||
p = "坤";
|
||||
break;
|
||||
case 3:
|
||||
case 7:
|
||||
case 11:
|
||||
p = "巽";
|
||||
break;
|
||||
default:
|
||||
p = LunarUtil.POSITION_GAN[monthGanIndex];
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取月太岁方位(默认流派2新的一月以节交接当天零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getMonthPositionTaiSui()
|
||||
{
|
||||
return getMonthPositionTaiSui(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取月太岁方位
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2为新的一月以节交接当天零点起算;3为新的一月以节交接准确时刻起算</param>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getMonthPositionTaiSui(int sect)
|
||||
{
|
||||
int monthZhiIndex;
|
||||
int monthGanIndex;
|
||||
switch (sect)
|
||||
{
|
||||
case 3:
|
||||
monthZhiIndex = this.monthZhiIndexExact;
|
||||
monthGanIndex = this.monthGanIndexExact;
|
||||
break;
|
||||
default:
|
||||
monthZhiIndex = this.monthZhiIndex;
|
||||
monthGanIndex = this.monthGanIndex;
|
||||
break;
|
||||
}
|
||||
return getMonthPositionTaiSui(monthZhiIndex, monthGanIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取月太岁方位描述(默认流派2新的一月以节交接当天零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getMonthPositionTaiSuiDesc()
|
||||
{
|
||||
return getMonthPositionTaiSuiDesc(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取月太岁方位描述
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2为新的一月以节交接当天零点起算;3为新的一月以节交接准确时刻起算</param>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getMonthPositionTaiSuiDesc(int sect)
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getMonthPositionTaiSui(sect)];
|
||||
}
|
||||
|
||||
protected string getDayPositionTaiSui(string dayInGanZhi, int yearZhiIndex)
|
||||
{
|
||||
string p;
|
||||
if ("甲子,乙丑,丙寅,丁卯,戊辰,已巳".Contains(dayInGanZhi))
|
||||
{
|
||||
p = "震";
|
||||
}
|
||||
else if ("丙子,丁丑,戊寅,已卯,庚辰,辛巳".Contains(dayInGanZhi))
|
||||
{
|
||||
p = "离";
|
||||
}
|
||||
else if ("戊子,已丑,庚寅,辛卯,壬辰,癸巳".Contains(dayInGanZhi))
|
||||
{
|
||||
p = "中";
|
||||
}
|
||||
else if ("庚子,辛丑,壬寅,癸卯,甲辰,乙巳".Contains(dayInGanZhi))
|
||||
{
|
||||
p = "兑";
|
||||
}
|
||||
else if ("壬子,癸丑,甲寅,乙卯,丙辰,丁巳".Contains(dayInGanZhi))
|
||||
{
|
||||
p = "坎";
|
||||
}
|
||||
else
|
||||
{
|
||||
p = LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日太岁方位(默认流派2新年以立春零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getDayPositionTaiSui()
|
||||
{
|
||||
return getDayPositionTaiSui(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日太岁方位
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2新年以立春零点起算;1新年以正月初一起算;3新年以立春节气交接的时刻起算</param>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getDayPositionTaiSui(int sect)
|
||||
{
|
||||
string dayInGanZhi;
|
||||
int yearZhiIndex;
|
||||
switch (sect)
|
||||
{
|
||||
case 1:
|
||||
dayInGanZhi = getDayInGanZhi();
|
||||
yearZhiIndex = this.yearZhiIndex;
|
||||
break;
|
||||
case 3:
|
||||
dayInGanZhi = getDayInGanZhi();
|
||||
yearZhiIndex = this.yearZhiIndexExact;
|
||||
break;
|
||||
default:
|
||||
dayInGanZhi = getDayInGanZhiExact2();
|
||||
yearZhiIndex = this.yearZhiIndexByLiChun;
|
||||
break;
|
||||
}
|
||||
return getDayPositionTaiSui(dayInGanZhi, yearZhiIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日太岁方位描述(默认流派2新年以立春零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getDayPositionTaiSuiDesc()
|
||||
{
|
||||
return getDayPositionTaiSuiDesc(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日太岁方位描述
|
||||
/// </summary>
|
||||
/// <param name="sect">流派:2新年以立春零点起算;1新年以正月初一起算;3新年以立春节气交接的时刻起算</param>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getDayPositionTaiSuiDesc(int sect)
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getDayPositionTaiSui(sect)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取年太岁方位描述(默认流派2新年以立春零点起算)
|
||||
/// </summary>
|
||||
/// <returns>方位描述</returns>
|
||||
public string getYearPositionTaiSuiDesc()
|
||||
{
|
||||
return getYearPositionTaiSuiDesc(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰喜神方位
|
||||
/// </summary>
|
||||
@@ -1732,100 +1947,164 @@ namespace com.nlf.calendar
|
||||
return LunarUtil.YUE_XIANG[day];
|
||||
}
|
||||
|
||||
protected NineStar getYearNineStar(string yearInGanZhi)
|
||||
{
|
||||
int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||
int yearOffset = 0;
|
||||
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1)
|
||||
{
|
||||
yearOffset = -1;
|
||||
}
|
||||
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
|
||||
int offset = (62 + yuan * 3 - index) % 9;
|
||||
if (0 == offset)
|
||||
{
|
||||
offset = 9;
|
||||
}
|
||||
return NineStar.fromIndex(offset - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值年九星(流年紫白星起例歌诀:年上吉星论甲子,逐年星逆中宫起;上中下作三元汇,一上四中七下兑。)
|
||||
/// </summary>
|
||||
/// <returns>值年九星</returns>
|
||||
/// <param name="sect">流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算</param>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getYearNineStar(int sect)
|
||||
{
|
||||
string yearInGanZhi;
|
||||
switch (sect)
|
||||
{
|
||||
case 1:
|
||||
yearInGanZhi = this.getYearInGanZhi();
|
||||
break;
|
||||
case 3:
|
||||
yearInGanZhi = this.getYearInGanZhiExact();
|
||||
break;
|
||||
default:
|
||||
yearInGanZhi = this.getYearInGanZhiByLiChun();
|
||||
break;
|
||||
}
|
||||
return getYearNineStar(yearInGanZhi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值年九星(默认流派2新年以立春零点起算。流年紫白星起例歌诀:年上吉星论甲子,逐年星逆中宫起;上中下作三元汇,一上四中七下兑。)
|
||||
/// </summary>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getYearNineStar()
|
||||
{
|
||||
int index = -(year - 1900) % 9;
|
||||
if (index < 0)
|
||||
return getYearNineStar(2);
|
||||
}
|
||||
|
||||
protected NineStar getMonthNineStar(int yearZhiIndex, int monthZhiIndex)
|
||||
{
|
||||
int index = yearZhiIndex % 3;
|
||||
int n = 27 - (index * 3);
|
||||
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX)
|
||||
{
|
||||
index += 9;
|
||||
n -= 3;
|
||||
}
|
||||
return new NineStar(index);
|
||||
int offset = (n - monthZhiIndex) % 9;
|
||||
return NineStar.fromIndex(offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值月九星(月紫白星歌诀:子午卯酉八白起,寅申巳亥二黑求,辰戌丑未五黄中。)
|
||||
/// </summary>
|
||||
/// <returns>值月九星</returns>
|
||||
/// <param name="sect">流派:2为新的一月以节交接当天零点起算;3为新的一月以节交接准确时刻起算</param>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getMonthNineStar(int sect)
|
||||
{
|
||||
int yearZhiIndex;
|
||||
int monthZhiIndex;
|
||||
switch (sect)
|
||||
{
|
||||
case 1:
|
||||
yearZhiIndex = this.yearZhiIndex;
|
||||
monthZhiIndex = this.monthZhiIndex;
|
||||
break;
|
||||
case 3:
|
||||
yearZhiIndex = this.yearZhiIndexExact;
|
||||
monthZhiIndex = this.monthZhiIndexExact;
|
||||
break;
|
||||
default:
|
||||
yearZhiIndex = this.yearZhiIndexByLiChun;
|
||||
monthZhiIndex = this.monthZhiIndex;
|
||||
break;
|
||||
}
|
||||
return getMonthNineStar(yearZhiIndex, monthZhiIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值月九星(流派2新的一月以节交接当天零点起算。月紫白星歌诀:子午卯酉八白起,寅申巳亥二黑求,辰戌丑未五黄中。)
|
||||
/// </summary>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getMonthNineStar()
|
||||
{
|
||||
int start = 2;
|
||||
string yearZhi = getYearZhi();
|
||||
if ("子午卯酉".Contains(yearZhi))
|
||||
{
|
||||
start = 8;
|
||||
}
|
||||
else if ("辰戌丑未".Contains(yearZhi))
|
||||
{
|
||||
start = 5;
|
||||
}
|
||||
// 寅月起,所以需要-2
|
||||
int monthIndex = monthZhiIndex - 2;
|
||||
if (monthIndex < 0)
|
||||
{
|
||||
monthIndex += 12;
|
||||
}
|
||||
int index = start - monthIndex - 1;
|
||||
while (index < 0)
|
||||
{
|
||||
index += 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
return getMonthNineStar(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值日九星(日家紫白星歌诀:日家白法不难求,二十四气六宫周;冬至雨水及谷雨,阳顺一七四中游;夏至处暑霜降后,九三六星逆行求。)
|
||||
/// </summary>
|
||||
/// <returns>值日九星</returns>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getDayNineStar()
|
||||
{
|
||||
//顺逆
|
||||
string solarYmd = solar.toYmd();
|
||||
string yuShui = jieQi["雨水"].toYmd();
|
||||
string guYu = jieQi["谷雨"].toYmd();
|
||||
string xiaZhi = jieQi["夏至"].toYmd();
|
||||
string chuShu = jieQi["处暑"].toYmd();
|
||||
string shuangJiang = jieQi["霜降"].toYmd();
|
||||
|
||||
int start = 6;
|
||||
bool asc = false;
|
||||
if (solarYmd.CompareTo(jieQi["冬至"].toYmd()) >= 0 && solarYmd.CompareTo(yuShui) < 0)
|
||||
Solar dongZhi = jieQi["冬至"];
|
||||
Solar dongZhi2 = jieQi["DONG_ZHI"];
|
||||
Solar xiaZhi = jieQi["夏至"];
|
||||
int dongZhiIndex = LunarUtil.getJiaZiIndex(dongZhi.getLunar().getDayInGanZhi());
|
||||
int dongZhiIndex2 = LunarUtil.getJiaZiIndex(dongZhi2.getLunar().getDayInGanZhi());
|
||||
int xiaZhiIndex = LunarUtil.getJiaZiIndex(xiaZhi.getLunar().getDayInGanZhi());
|
||||
Solar solarShunBai;
|
||||
Solar solarShunBai2;
|
||||
Solar solarNiZi;
|
||||
if (dongZhiIndex > 29)
|
||||
{
|
||||
asc = true;
|
||||
start = 1;
|
||||
solarShunBai = dongZhi.next(60 - dongZhiIndex);
|
||||
}
|
||||
else if (solarYmd.CompareTo(yuShui) >= 0 && solarYmd.CompareTo(guYu) < 0)
|
||||
else
|
||||
{
|
||||
asc = true;
|
||||
start = 7;
|
||||
solarShunBai = dongZhi.next(-dongZhiIndex);
|
||||
}
|
||||
else if (solarYmd.CompareTo(guYu) >= 0 && solarYmd.CompareTo(xiaZhi) < 0)
|
||||
string solarShunBaiYmd = solarShunBai.toYmd();
|
||||
if (dongZhiIndex2 > 29)
|
||||
{
|
||||
asc = true;
|
||||
start = 4;
|
||||
solarShunBai2 = dongZhi2.next(60 - dongZhiIndex2);
|
||||
}
|
||||
else if (solarYmd.CompareTo(xiaZhi) >= 0 && solarYmd.CompareTo(chuShu) < 0)
|
||||
else
|
||||
{
|
||||
start = 9;
|
||||
solarShunBai2 = dongZhi2.next(-dongZhiIndex2);
|
||||
}
|
||||
else if (solarYmd.CompareTo(chuShu) >= 0 && solarYmd.CompareTo(shuangJiang) < 0)
|
||||
string solarShunBaiYmd2 = solarShunBai2.toYmd();
|
||||
if (xiaZhiIndex > 29)
|
||||
{
|
||||
start = 3;
|
||||
solarNiZi = xiaZhi.next(60 - xiaZhiIndex);
|
||||
}
|
||||
int ganZhiIndex = LunarUtil.getJiaZiIndex(getDayInGanZhi()) % 9;
|
||||
int index = asc ? start + ganZhiIndex - 1 : start - ganZhiIndex - 1;
|
||||
if (index > 8)
|
||||
else
|
||||
{
|
||||
index -= 9;
|
||||
solarNiZi = xiaZhi.next(-xiaZhiIndex);
|
||||
}
|
||||
if (index < 0)
|
||||
string solarNiZiYmd = solarNiZi.toYmd();
|
||||
int offset = 0;
|
||||
if (solarYmd.CompareTo(solarShunBaiYmd) >= 0 && solarYmd.CompareTo(solarNiZiYmd) < 0)
|
||||
{
|
||||
index += 9;
|
||||
offset = ExactDate.getDaysBetween(solarShunBai.getCalendar(), this.getSolar().getCalendar()) % 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
else if (solarYmd.CompareTo(solarNiZiYmd) >= 0 && solarYmd.CompareTo(solarShunBaiYmd2) < 0)
|
||||
{
|
||||
offset = 8 - (ExactDate.getDaysBetween(solarNiZi.getCalendar(), this.getSolar().getCalendar()) % 9);
|
||||
}
|
||||
else if (solarYmd.CompareTo(solarShunBaiYmd2) >= 0)
|
||||
{
|
||||
offset = ExactDate.getDaysBetween(solarShunBai2.getCalendar(), this.getSolar().getCalendar()) % 9;
|
||||
}
|
||||
else if (solarYmd.CompareTo(solarShunBaiYmd) < 0)
|
||||
{
|
||||
offset = (8 + ExactDate.getDaysBetween(this.getSolar().getCalendar(), solarShunBai.getCalendar())) % 9;
|
||||
}
|
||||
return NineStar.fromIndex(offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1841,26 +2120,22 @@ namespace com.nlf.calendar
|
||||
{
|
||||
asc = true;
|
||||
}
|
||||
int start = asc ? 7 : 3;
|
||||
else if (solarYmd.CompareTo(jieQi["DONG_ZHI"].toYmd()) >= 0)
|
||||
{
|
||||
asc = true;
|
||||
}
|
||||
int start = asc ? 6 : 2;
|
||||
string dayZhi = getDayZhi();
|
||||
if ("子午卯酉".Contains(dayZhi))
|
||||
{
|
||||
start = asc ? 1 : 9;
|
||||
start = asc ? 0 : 8;
|
||||
}
|
||||
else if ("辰戌丑未".Contains(dayZhi))
|
||||
{
|
||||
start = asc ? 4 : 6;
|
||||
start = asc ? 3 : 5;
|
||||
}
|
||||
int index = asc ? start + timeZhiIndex - 1 : start - timeZhiIndex - 1;
|
||||
if (index > 8)
|
||||
{
|
||||
index -= 9;
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
index += 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
int index = asc ? start + timeZhiIndex : start + 9 - timeZhiIndex;
|
||||
return new NineStar(index % 9);
|
||||
}
|
||||
|
||||
public Dictionary<string, Solar> getJieQiTable()
|
||||
@@ -1874,20 +2149,15 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getNextJie()
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2];
|
||||
}
|
||||
return getNearJieQi(true, conditions);
|
||||
return getNextJie(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上一节(逆推的第一个节)
|
||||
/// 获取下一节(顺推的第一个节)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevJie()
|
||||
public JieQi getNextJie(bool wholeDay)
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
string[] conditions = new string[l];
|
||||
@@ -1895,7 +2165,32 @@ namespace com.nlf.calendar
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2];
|
||||
}
|
||||
return getNearJieQi(false, conditions);
|
||||
return getNearJieQi(true, conditions, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上一节(逆推的第一个节)
|
||||
/// </summary>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevJie()
|
||||
{
|
||||
return getPrevJie(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上一节(逆推的第一个节)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevJie(bool wholeDay)
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2];
|
||||
}
|
||||
return getNearJieQi(false, conditions, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1903,6 +2198,16 @@ namespace com.nlf.calendar
|
||||
/// </summary>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getNextQi()
|
||||
{
|
||||
return getNextQi(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一气令(顺推的第一个气令)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getNextQi(bool wholeDay)
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
string[] conditions = new string[l];
|
||||
@@ -1910,7 +2215,7 @@ namespace com.nlf.calendar
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
|
||||
}
|
||||
return getNearJieQi(true, conditions);
|
||||
return getNearJieQi(true, conditions, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1918,6 +2223,16 @@ namespace com.nlf.calendar
|
||||
/// </summary>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevQi()
|
||||
{
|
||||
return getPrevQi(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上一气令(逆推的第一个气令)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevQi(bool wholeDay)
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
string[] conditions = new string[l];
|
||||
@@ -1925,7 +2240,7 @@ namespace com.nlf.calendar
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
|
||||
}
|
||||
return getNearJieQi(false, conditions);
|
||||
return getNearJieQi(false, conditions, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1934,7 +2249,17 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getNextJieQi()
|
||||
{
|
||||
return getNearJieQi(true, null);
|
||||
return getNextJieQi(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一节气(顺推的第一个节气)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getNextJieQi(bool wholeDay)
|
||||
{
|
||||
return getNearJieQi(true, null, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1943,7 +2268,17 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevJieQi()
|
||||
{
|
||||
return getNearJieQi(false, null);
|
||||
return getPrevJieQi(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上一节气(逆推的第一个节气)
|
||||
/// </summary>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
public JieQi getPrevJieQi(bool wholeDay)
|
||||
{
|
||||
return getNearJieQi(false, null, wholeDay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1951,8 +2286,9 @@ namespace com.nlf.calendar
|
||||
/// </summary>
|
||||
/// <param name="forward">是否顺推,true为顺推,false为逆推</param>
|
||||
/// <param name="conditions">过滤条件,如果设置过滤条件,仅返回匹配该名称的</param>
|
||||
/// <param name="wholeDay">是否按天计</param>
|
||||
/// <returns>节气</returns>
|
||||
private JieQi getNearJieQi(bool forward, string[] conditions)
|
||||
private JieQi getNearJieQi(bool forward, string[] conditions, bool wholeDay)
|
||||
{
|
||||
string name = null;
|
||||
Solar near = null;
|
||||
@@ -1968,7 +2304,7 @@ namespace com.nlf.calendar
|
||||
}
|
||||
}
|
||||
bool filter = filters.Count > 0;
|
||||
string today = solar.toYmdHms();
|
||||
string today = wholeDay ? solar.toYmd() : solar.toYmdHms();
|
||||
foreach (KeyValuePair<string, Solar> entry in jieQi)
|
||||
{
|
||||
string jq = entry.Key;
|
||||
@@ -1980,18 +2316,27 @@ namespace com.nlf.calendar
|
||||
}
|
||||
}
|
||||
Solar current = entry.Value;
|
||||
string day = current.toYmdHms();
|
||||
string day = wholeDay ? current.toYmd() : current.toYmdHms();
|
||||
if (forward)
|
||||
{
|
||||
if (day.CompareTo(today) < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (null == near || day.CompareTo(near.toYmdHms()) < 0)
|
||||
if (null == near)
|
||||
{
|
||||
name = jq;
|
||||
near = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
string nearDay = wholeDay ? near.toYmd() : near.toYmdHms();
|
||||
if (day.CompareTo(nearDay) < 0)
|
||||
{
|
||||
name = jq;
|
||||
near = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1999,11 +2344,20 @@ namespace com.nlf.calendar
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (null == near || day.CompareTo(near.toYmdHms()) > 0)
|
||||
if (null == near)
|
||||
{
|
||||
name = jq;
|
||||
near = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
string nearDay = wholeDay ? near.toYmd() : near.toYmdHms();
|
||||
if (day.CompareTo(nearDay) > 0)
|
||||
{
|
||||
name = jq;
|
||||
near = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2011,7 +2365,7 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new JieQi(name, near);
|
||||
return new JieQi(convertJieQi(name), near);
|
||||
}
|
||||
|
||||
protected string convertJieQi(string name)
|
||||
@@ -2054,18 +2408,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气名称</returns>
|
||||
public string getJieQi()
|
||||
{
|
||||
string name = "";
|
||||
foreach (KeyValuePair<string, Solar> jq in jieQi)
|
||||
{
|
||||
Solar d = jq.Value;
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
name = jq.Key;
|
||||
break;
|
||||
return convertJieQi(jq.Key);
|
||||
}
|
||||
|
||||
}
|
||||
return convertJieQi(name);
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2074,8 +2426,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气对象</returns>
|
||||
public JieQi getCurrentJieQi()
|
||||
{
|
||||
string name = getJieQi();
|
||||
return name.Length > 0 ? new JieQi(name, solar) : null;
|
||||
foreach (KeyValuePair<string, Solar> jq in jieQi)
|
||||
{
|
||||
Solar d = jq.Value;
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
return new JieQi(convertJieQi(jq.Key), d);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2084,8 +2444,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气对象</returns>
|
||||
public JieQi getCurrentJie()
|
||||
{
|
||||
string name = getJie();
|
||||
return name.Length > 0 ? new JieQi(name, solar) : null;
|
||||
for (int i = 0, j = JIE_QI_IN_USE.Length; i < j; i += 2)
|
||||
{
|
||||
string key = JIE_QI_IN_USE[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
return new JieQi(convertJieQi(key), d);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2094,8 +2462,16 @@ namespace com.nlf.calendar
|
||||
/// <returns>节气对象</returns>
|
||||
public JieQi getCurrentQi()
|
||||
{
|
||||
string name = getQi();
|
||||
return name.Length > 0 ? new JieQi(name, solar) : null;
|
||||
for (int i = 1, j = JIE_QI_IN_USE.Length; i < j; i += 2)
|
||||
{
|
||||
string key = JIE_QI_IN_USE[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
return new JieQi(convertJieQi(key), d);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string toFullString()
|
||||
@@ -2549,7 +2925,7 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
int days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
return new ShuJiu(LunarUtil.NUMBER[days / 9 + 1] + "九", days % 9 + 1);
|
||||
}
|
||||
|
||||
@@ -2574,20 +2950,20 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
int days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("初伏", days + 1);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("中伏", days + 1);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
DateTime liQiuCalendar = ExactDate.fromYmd(liQiu.getYear(), liQiu.getMonth(), liQiu.getDay());
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
if (liQiuCalendar.CompareTo(startCalendar) <= 0)
|
||||
{
|
||||
if (days < 10)
|
||||
@@ -2602,7 +2978,7 @@ namespace com.nlf.calendar
|
||||
return new Fu("中伏", days + 11);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("末伏", days + 1);
|
||||
@@ -2625,7 +3001,7 @@ namespace com.nlf.calendar
|
||||
/// <returns>物候</returns>
|
||||
public string getWuHou()
|
||||
{
|
||||
JieQi jieQi = getPrevJieQi();
|
||||
JieQi jieQi = getPrevJieQi(true);
|
||||
string name = jieQi.getName();
|
||||
int offset = 0;
|
||||
for (int i = 0, j = JIE_QI.Length; i < j; i++)
|
||||
@@ -2636,13 +3012,20 @@ namespace com.nlf.calendar
|
||||
break;
|
||||
}
|
||||
}
|
||||
DateTime currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
Solar startSolar = jieQi.getSolar();
|
||||
DateTime startCalendar = ExactDate.fromYmd(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay());
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
int days = ExactDate.getDaysBetween(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay(), solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.Length];
|
||||
}
|
||||
|
||||
public string getHou()
|
||||
{
|
||||
JieQi jieQi = getPrevJieQi(true);
|
||||
string name = jieQi.getName();
|
||||
Solar startSolar = jieQi.getSolar();
|
||||
int days = ExactDate.getDaysBetween(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay(), solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
return name + " " + LunarUtil.HOU[(days / 5) % LunarUtil.HOU.Length];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日禄
|
||||
/// </summary>
|
||||
|
||||
@@ -101,6 +101,65 @@ namespace com.nlf.calendar
|
||||
return firstJulianDay;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取太岁方位
|
||||
/// </summary>
|
||||
/// <returns>太岁方位,如艮</returns>
|
||||
public string getPositionTaiSui()
|
||||
{
|
||||
string p;
|
||||
int m = Math.Abs(month);
|
||||
switch (m)
|
||||
{
|
||||
case 1:
|
||||
case 5:
|
||||
case 9:
|
||||
p = "艮";
|
||||
break;
|
||||
case 3:
|
||||
case 7:
|
||||
case 11:
|
||||
p = "坤";
|
||||
break;
|
||||
case 4:
|
||||
case 8:
|
||||
case 12:
|
||||
p = "巽";
|
||||
break;
|
||||
default:
|
||||
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()];
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取太岁方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionTaiSuiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionTaiSui()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取月九星
|
||||
/// </summary>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getNineStar()
|
||||
{
|
||||
int index = LunarYear.fromYear(year).getZhiIndex() % 3;
|
||||
int m = Math.Abs(month);
|
||||
int monthZhiIndex = (13 + m) % 12;
|
||||
int n = 27 - (index * 3);
|
||||
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX)
|
||||
{
|
||||
n -= 3;
|
||||
}
|
||||
int offset = (n - monthZhiIndex) % 9;
|
||||
return NineStar.fromIndex(offset);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return year + "年" + (isLeap() ? "闰" : "") + LunarUtil.MONTH[Math.Abs(month)] + "月(" + dayCount + "天)";
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using com.nlf.calendar.util;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
@@ -10,6 +11,16 @@ namespace com.nlf.calendar
|
||||
/// </summary>
|
||||
public class LunarYear
|
||||
{
|
||||
/// <summary>
|
||||
/// 元
|
||||
/// </summary>
|
||||
private static readonly string[] YUAN = { "下", "上", "中" };
|
||||
|
||||
/// <summary>
|
||||
/// 运
|
||||
/// </summary>
|
||||
private static readonly string[] YUN = { "七", "八", "九", "一", "二", "三", "四", "五", "六" };
|
||||
|
||||
/// <summary>
|
||||
/// 闰冬月年份
|
||||
/// </summary>
|
||||
@@ -41,6 +52,16 @@ namespace com.nlf.calendar
|
||||
/// </summary>
|
||||
private int year;
|
||||
|
||||
/// <summary>
|
||||
/// 天干下标
|
||||
/// </summary>
|
||||
private int ganIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 地支下标
|
||||
/// </summary>
|
||||
private int zhiIndex;
|
||||
|
||||
private List<LunarMonth> months = new List<LunarMonth>();
|
||||
|
||||
private List<double> jieQiJulianDays = new List<double>();
|
||||
@@ -52,6 +73,19 @@ namespace com.nlf.calendar
|
||||
public LunarYear(int lunarYear)
|
||||
{
|
||||
this.year = lunarYear;
|
||||
int offset = lunarYear - 4;
|
||||
int yearGanIndex = offset % 10;
|
||||
int yearZhiIndex = offset % 12;
|
||||
if (yearGanIndex < 0)
|
||||
{
|
||||
yearGanIndex += 10;
|
||||
}
|
||||
if (yearZhiIndex < 0)
|
||||
{
|
||||
yearZhiIndex += 12;
|
||||
}
|
||||
this.ganIndex = yearGanIndex;
|
||||
this.zhiIndex = yearZhiIndex;
|
||||
compute();
|
||||
}
|
||||
|
||||
@@ -192,6 +226,51 @@ namespace com.nlf.calendar
|
||||
return year;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取天干序号,从0开始
|
||||
/// </summary>
|
||||
/// <returns>序号</returns>
|
||||
public int getGanIndex()
|
||||
{
|
||||
return ganIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取地支序号,从0开始
|
||||
/// </summary>
|
||||
/// <returns>序号</returns>
|
||||
public int getZhiIndex()
|
||||
{
|
||||
return zhiIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取天干
|
||||
/// </summary>
|
||||
/// <returns>天干</returns>
|
||||
public string getGan()
|
||||
{
|
||||
return LunarUtil.GAN[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取地支
|
||||
/// </summary>
|
||||
/// <returns>地支</returns>
|
||||
public string getZhi()
|
||||
{
|
||||
return LunarUtil.ZHI[zhiIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取干支
|
||||
/// </summary>
|
||||
/// <returns>干支</returns>
|
||||
public string getGanZhi()
|
||||
{
|
||||
return getGan() + getZhi();
|
||||
}
|
||||
|
||||
public List<LunarMonth> getMonths()
|
||||
{
|
||||
return months;
|
||||
@@ -236,60 +315,313 @@ namespace com.nlf.calendar
|
||||
return year + "年";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取治水(正月第一个辰日是初几,就是几龙治水)
|
||||
/// </summary>
|
||||
/// <returns>治水,如:二龙治水</returns>
|
||||
public string getZhiShui()
|
||||
protected string getZaoByGan(int index, string name)
|
||||
{
|
||||
int offset = 4 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 12;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "龙治水";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分饼(正月第一个丙日是初几,就是几人分饼)
|
||||
/// </summary>
|
||||
/// <returns>分饼,如:六人分饼</returns>
|
||||
public string getFenBing()
|
||||
{
|
||||
int offset = 2 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
|
||||
int offset = index - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 10;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "人分饼";
|
||||
return new Regex("几", RegexOptions.Singleline).Replace(name, LunarUtil.NUMBER[offset + 1], 1);
|
||||
}
|
||||
|
||||
protected string getZaoByZhi(int index, string name)
|
||||
{
|
||||
int offset = index - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 12;
|
||||
}
|
||||
return new Regex("几", RegexOptions.Singleline).Replace(name, LunarUtil.NUMBER[offset + 1], 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几鼠偷粮
|
||||
/// </summary>
|
||||
/// <returns>几鼠偷粮</returns>
|
||||
public string getTouLiang()
|
||||
{
|
||||
return getZaoByZhi(0, "几鼠偷粮");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取草子几分
|
||||
/// </summary>
|
||||
/// <returns>草子几分</returns>
|
||||
public string getCaoZi()
|
||||
{
|
||||
return getZaoByZhi(0, "草子几分");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取耕田(正月第一个丑日是初几,就是几牛耕田)
|
||||
/// </summary>
|
||||
/// <returns>耕田,如:六牛耕田</returns>
|
||||
/// <returns>几牛耕田</returns>
|
||||
public string getGengTian()
|
||||
{
|
||||
int offset = 1 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 12;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "牛耕田";
|
||||
return getZaoByZhi(1, "几牛耕田");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取花收几分
|
||||
/// </summary>
|
||||
/// <returns>花收几分</returns>
|
||||
public string getHuaShou()
|
||||
{
|
||||
return getZaoByZhi(3, "花收几分");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取治水(正月第一个辰日是初几,就是几龙治水)
|
||||
/// </summary>
|
||||
/// <returns>几龙治水</returns>
|
||||
public string getZhiShui()
|
||||
{
|
||||
return getZaoByZhi(4, "几龙治水");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几马驮谷
|
||||
/// </summary>
|
||||
/// <returns>几马驮谷</returns>
|
||||
public string getTuoGu()
|
||||
{
|
||||
return getZaoByZhi(6, "几马驮谷");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几鸡抢米
|
||||
/// </summary>
|
||||
/// <returns>几鸡抢米</returns>
|
||||
public string getQiangMi()
|
||||
{
|
||||
return getZaoByZhi(9, "几鸡抢米");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几姑看蚕
|
||||
/// </summary>
|
||||
/// <returns>几姑看蚕</returns>
|
||||
public string getKanCan()
|
||||
{
|
||||
return getZaoByZhi(9, "几姑看蚕");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几屠共猪
|
||||
/// </summary>
|
||||
/// <returns>几屠共猪</returns>
|
||||
public string getGongZhu()
|
||||
{
|
||||
return getZaoByZhi(11, "几屠共猪");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取甲田几分
|
||||
/// </summary>
|
||||
/// <returns>甲田几分</returns>
|
||||
public string getJiaTian()
|
||||
{
|
||||
return getZaoByGan(0, "甲田几分");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分饼(正月第一个丙日是初几,就是几人分饼)
|
||||
/// </summary>
|
||||
/// <returns>几人分饼</returns>
|
||||
public string getFenBing()
|
||||
{
|
||||
return getZaoByGan(2, "几人分饼");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取得金(正月第一个辛日是初几,就是几日得金)
|
||||
/// </summary>
|
||||
/// <returns>得金,如:一日得金</returns>
|
||||
/// <returns>几日得金</returns>
|
||||
public string getDeJin()
|
||||
{
|
||||
int offset = 7 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
|
||||
if (offset < 0)
|
||||
return getZaoByGan(7, "几日得金");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几人几丙
|
||||
/// </summary>
|
||||
/// <returns>几人几丙</returns>
|
||||
public string getRenBing()
|
||||
{
|
||||
return getZaoByGan(2, getZaoByZhi(2, "几人几丙"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取几人几锄
|
||||
/// </summary>
|
||||
/// <returns>几人几锄</returns>
|
||||
public string getRenChu()
|
||||
{
|
||||
return getZaoByGan(3, getZaoByZhi(2, "几人几锄"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取三元
|
||||
/// </summary>
|
||||
/// <returns>元</returns>
|
||||
public string getYuan()
|
||||
{
|
||||
return YUAN[((year + 2696) / 60) % 3] + "元";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取九运
|
||||
/// </summary>
|
||||
/// <returns>运</returns>
|
||||
public string getYun()
|
||||
{
|
||||
return YUN[((year + 2696) / 20) % 9] + "运";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取九星
|
||||
/// </summary>
|
||||
/// <returns>九星</returns>
|
||||
public NineStar getNineStar()
|
||||
{
|
||||
int index = LunarUtil.getJiaZiIndex(getGanZhi()) + 1;
|
||||
int yuan = ((this.year + 2696) / 60) % 3;
|
||||
int offset = (62 + yuan * 3 - index) % 9;
|
||||
if (0 == offset)
|
||||
{
|
||||
offset += 10;
|
||||
offset = 9;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "日得金";
|
||||
return NineStar.fromIndex(offset - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取喜神方位
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionXi()
|
||||
{
|
||||
return LunarUtil.POSITION_XI[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取喜神方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionXiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionXi()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取阳贵神方位
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionYangGui()
|
||||
{
|
||||
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取阳贵神方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionYangGuiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionYangGui()];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取阴贵神方位
|
||||
*
|
||||
* @return 阴贵神方位,如艮
|
||||
*/
|
||||
public string getPositionYinGui()
|
||||
{
|
||||
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取阴贵神方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionYinGuiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionYinGui()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取福神方位(默认流派:2)
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionFu()
|
||||
{
|
||||
return getPositionFu(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取福神方位
|
||||
/// </summary>
|
||||
/// <param name="sect">流派,1或2</param>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionFu(int sect)
|
||||
{
|
||||
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取福神方位描述(默认流派:2)
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionFuDesc()
|
||||
{
|
||||
return getPositionFuDesc(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取福神方位描述
|
||||
/// </summary>
|
||||
/// <param name="sect">流派,1或2</param>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionFuDesc(int sect)
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionFu(sect)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取财神方位
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionCai()
|
||||
{
|
||||
return LunarUtil.POSITION_CAI[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取财神方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionCaiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionCai()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取太岁方位
|
||||
/// </summary>
|
||||
/// <returns>方位,如艮</returns>
|
||||
public string getPositionTaiSui()
|
||||
{
|
||||
return LunarUtil.POSITION_TAI_SUI_YEAR[zhiIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取太岁方位描述
|
||||
/// </summary>
|
||||
/// <returns>方位描述,如东北</returns>
|
||||
public string getPositionTaiSuiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionTaiSui()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
[assembly: AssemblyVersion("1.2.13.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.13.0")]
|
||||
[assembly: AssemblyVersion("1.2.14.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.14.0")]
|
||||
|
||||
@@ -261,7 +261,7 @@ namespace com.nlf.calendar
|
||||
{
|
||||
offsetYear = offsetYear + 60;
|
||||
}
|
||||
int startYear = today.getYear() - offsetYear;
|
||||
int startYear = lunar.getYear() - offsetYear;
|
||||
int hour = 0;
|
||||
string timeZhi = timeGanZhi.Substring(1);
|
||||
for (int i = 0, j = LunarUtil.ZHI.Length; i < j; i++)
|
||||
|
||||
@@ -130,11 +130,12 @@ namespace com.nlf.calendar
|
||||
{
|
||||
DateTime firstDay = ExactDate.fromYmd(year, month, 1);
|
||||
int firstDayWeek = Convert.ToInt32(firstDay.DayOfWeek.ToString("d"));
|
||||
if (firstDayWeek == 0)
|
||||
int offset = firstDayWeek - start;
|
||||
if (offset < 0)
|
||||
{
|
||||
firstDayWeek = 7;
|
||||
offset += 7;
|
||||
}
|
||||
return (int)Math.Ceiling((day + firstDayWeek - start) * 1D / SolarUtil.WEEK.Length);
|
||||
return (int)Math.Ceiling((day + offset) * 1D / 7);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
68
lunar/Tao.cs
68
lunar/Tao.cs
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using com.nlf.calendar.util;
|
||||
using System;
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
/// <summary>
|
||||
@@ -166,6 +167,73 @@ namespace com.nlf.calendar
|
||||
return TaoUtil.BA_HUI.ContainsKey(lunar.getDayInGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否明戊日
|
||||
/// </summary>
|
||||
/// <returns>true/false</returns>
|
||||
public bool isDayMingWu()
|
||||
{
|
||||
return "戊".Equals(lunar.getDayGan());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否暗戊日
|
||||
/// </summary>
|
||||
/// <returns>true/false</returns>
|
||||
public bool isDayAnWu()
|
||||
{
|
||||
return lunar.getDayZhi().Equals(TaoUtil.AN_WU[Math.Abs(getMonth()) - 1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否戊日
|
||||
/// </summary>
|
||||
/// <returns>true/false</returns>
|
||||
public bool isDayWu()
|
||||
{
|
||||
return isDayMingWu() || isDayAnWu();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否天赦日
|
||||
/// </summary>
|
||||
/// <returns>true/false</returns>
|
||||
public bool isDayTianShe()
|
||||
{
|
||||
bool ret = false;
|
||||
string mz = lunar.getMonthZhi();
|
||||
string dgz = lunar.getDayInGanZhi();
|
||||
if ("寅卯辰".Contains(mz))
|
||||
{
|
||||
if ("戊寅".Equals(dgz))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
else if ("巳午未".Contains(mz))
|
||||
{
|
||||
if ("甲午".Equals(dgz))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
else if ("申酉戌".Contains(mz))
|
||||
{
|
||||
if ("戊申".Equals(dgz))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
else if ("亥子丑".Contains(mz))
|
||||
{
|
||||
if ("甲子".Equals(dgz))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string toString()
|
||||
{
|
||||
return getYearInChinese() + "年" + getMonthInChinese() + "月" + getDayInChinese();
|
||||
|
||||
@@ -59,9 +59,7 @@ namespace com.nlf.calendar.eightchar
|
||||
int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().Substring(11, 5));
|
||||
// 时辰差
|
||||
int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
|
||||
DateTime endCalendar = ExactDate.fromYmd(end.getYear(), end.getMonth(), end.getDay());
|
||||
DateTime startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
|
||||
int dayDiff = endCalendar.Subtract(startCalendar).Days;
|
||||
int dayDiff = ExactDate.getDaysBetween(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
|
||||
if (hourDiff < 0)
|
||||
{
|
||||
hourDiff += 12;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<PackageProjectUrl>http://6tail.cn/calendar/api.html</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/6tail/lunar-csharp.git</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>1.2.13.0</Version>
|
||||
<Version>1.2.14.0</Version>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace com.nlf.calendar.util
|
||||
/// </summary>
|
||||
public static readonly string[] LIU_YAO = { "先胜", "友引", "先负", "佛灭", "大安", "赤口" };
|
||||
|
||||
/// <summary>
|
||||
/// 候
|
||||
/// </summary>
|
||||
public static readonly string[] HOU = { "初候", "二候", "三候" };
|
||||
|
||||
/// <summary>
|
||||
/// 物候
|
||||
/// </summary>
|
||||
@@ -77,6 +82,21 @@ namespace com.nlf.calendar.util
|
||||
/// </summary>
|
||||
public static readonly string[] POSITION_TAI_MONTH = { "占房床", "占户窗", "占门堂", "占厨灶", "占房床", "占床仓", "占碓磨", "占厕户", "占门房", "占房床", "占灶炉", "占房床" };
|
||||
|
||||
/// <summary>
|
||||
/// 年太岁方位
|
||||
/// </summary>
|
||||
public static readonly string[] POSITION_TAI_SUI_YEAR = { "坎", "艮", "艮", "震", "巽", "巽", "离", "坤", "坤", "兑", "坎", "坎" };
|
||||
|
||||
/// <summary>
|
||||
/// 天干方位
|
||||
/// </summary>
|
||||
public static readonly string[] POSITION_GAN = { "震", "震", "离", "离", "中", "中", "兑", "兑", "坎", "坎" };
|
||||
|
||||
/// <summary>
|
||||
/// 地支方位
|
||||
/// </summary>
|
||||
public static readonly string[] POSITION_ZHI = { "坎", "中", "震", "震", "中", "离", "离", "中", "兑", "兑", "中", "坎" };
|
||||
|
||||
/// <summary>
|
||||
/// 地支
|
||||
/// </summary>
|
||||
|
||||
@@ -127,6 +127,16 @@ namespace com.nlf.calendar.util
|
||||
return DateTime.IsLeapYear(year);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某年有多少天(平年365天,闰年366天)
|
||||
/// </summary>
|
||||
/// <param name="year">年</param>
|
||||
/// <returns>天数</returns>
|
||||
public static int getDaysOfYear(int year)
|
||||
{
|
||||
return isLeapYear(year) ? 366 : 365;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某年某月有多少天
|
||||
/// </summary>
|
||||
@@ -135,9 +145,35 @@ namespace com.nlf.calendar.util
|
||||
/// <returns>天数</returns>
|
||||
public static int getDaysOfMonth(int year, int month)
|
||||
{
|
||||
if (1582 == year && 10 == month)
|
||||
{
|
||||
return 21;
|
||||
}
|
||||
return DateTime.DaysInMonth(year, month);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某天为当年的第几天
|
||||
/// </summary>
|
||||
/// <param name="year">年</param>
|
||||
/// <param name="month">月</param>
|
||||
/// <param name="day">日</param>
|
||||
/// <returns>第几天</returns>
|
||||
public static int getDaysInYear(int year, int month, int day)
|
||||
{
|
||||
int days = 0;
|
||||
for (int i = 1; i < month; i++)
|
||||
{
|
||||
days += getDaysOfMonth(year, i);
|
||||
}
|
||||
days += day;
|
||||
if (1582 == year && 10 == month && day >= 15)
|
||||
{
|
||||
days -= 10;
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某年某月有多少周
|
||||
/// </summary>
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace com.nlf.calendar.util
|
||||
/// </summary>
|
||||
public static readonly string[] WU_LA = { "1-1", "5-5", "7-7", "10-1", "12-8" };
|
||||
|
||||
/// <summary>
|
||||
/// 暗戊
|
||||
/// </summary>
|
||||
public static readonly string[] AN_WU = { "未", "戌", "辰", "寅", "午", "子", "酉", "申", "巳", "亥", "卯", "丑" };
|
||||
|
||||
/// <summary>
|
||||
/// 八会日
|
||||
/// </summary>
|
||||
|
||||
@@ -119,14 +119,14 @@ namespace test
|
||||
public void test23()
|
||||
{
|
||||
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
|
||||
Assert.AreEqual("五黄土玉衡", lunar.getYearNineStar().toString());
|
||||
Assert.AreEqual("六白金开阳", lunar.getYearNineStar().toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test24()
|
||||
{
|
||||
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
|
||||
Assert.AreEqual("三碧木天玑", lunar.getYearNineStar().toString());
|
||||
Assert.AreEqual("四绿木天权", lunar.getYearNineStar().toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
|
||||
@@ -138,7 +138,37 @@ namespace test
|
||||
Assert.AreEqual("蚯蚓结", lunar.getWuHou(), solar.toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test11()
|
||||
{
|
||||
Solar solar = new Solar(2021, 12, 21);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("冬至 初候", lunar.getHou(), solar.toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test12()
|
||||
{
|
||||
Solar solar = new Solar(2021, 12, 26);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("冬至 二候", lunar.getHou(), solar.toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test13()
|
||||
{
|
||||
Solar solar = new Solar(2021, 12, 31);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("冬至 三候", lunar.getHou(), solar.toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test14()
|
||||
{
|
||||
Solar solar = new Solar(2022, 1, 5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("小寒 初候", lunar.getHou(), solar.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -102,6 +102,96 @@ namespace test
|
||||
Assert.AreEqual("三日得金", year.getDeJin());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test6()
|
||||
{
|
||||
LunarYear year = new LunarYear(1864);
|
||||
Assert.AreEqual("上元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test7()
|
||||
{
|
||||
LunarYear year = new LunarYear(1923);
|
||||
Assert.AreEqual("上元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test8()
|
||||
{
|
||||
LunarYear year = new LunarYear(1924);
|
||||
Assert.AreEqual("中元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test9()
|
||||
{
|
||||
LunarYear year = new LunarYear(1983);
|
||||
Assert.AreEqual("中元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test10()
|
||||
{
|
||||
LunarYear year = new LunarYear(1984);
|
||||
Assert.AreEqual("下元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test11()
|
||||
{
|
||||
LunarYear year = new LunarYear(2043);
|
||||
Assert.AreEqual("下元", year.getYuan());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test12()
|
||||
{
|
||||
LunarYear year = new LunarYear(1864);
|
||||
Assert.AreEqual("一运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test13()
|
||||
{
|
||||
LunarYear year = new LunarYear(1883);
|
||||
Assert.AreEqual("一运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test14()
|
||||
{
|
||||
LunarYear year = new LunarYear(1884);
|
||||
Assert.AreEqual("二运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test15()
|
||||
{
|
||||
LunarYear year = new LunarYear(1903);
|
||||
Assert.AreEqual("二运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test16()
|
||||
{
|
||||
LunarYear year = new LunarYear(1904);
|
||||
Assert.AreEqual("三运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test17()
|
||||
{
|
||||
LunarYear year = new LunarYear(1923);
|
||||
Assert.AreEqual("三运", year.getYun());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test18()
|
||||
{
|
||||
LunarYear year = new LunarYear(2004);
|
||||
Assert.AreEqual("八运", year.getYun());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user