mirror of
https://gitee.com/6tail/lunar-csharp.git
synced 2025-12-06 10:19:07 +08:00
v1.2.6 新增治水、分饼、耕田、得金、日禄;新增时辰LunarTime;新增获取当天的所有时辰。
This commit is contained in:
@@ -284,8 +284,8 @@ namespace com.nlf.calendar
|
||||
int zExact = yearZhiIndex;
|
||||
|
||||
int solarYear = solar.getYear();
|
||||
String solarYmd = solar.toYmd();
|
||||
String solarYmdHms = solar.toYmdHms();
|
||||
string solarYmd = solar.toYmd();
|
||||
string solarYmdHms = solar.toYmdHms();
|
||||
|
||||
//获取立春的阳历时刻
|
||||
Solar liChun = jieQi["立春"];
|
||||
@@ -293,8 +293,8 @@ namespace com.nlf.calendar
|
||||
{
|
||||
liChun = jieQi["LI_CHUN"];
|
||||
}
|
||||
String liChunYmd = liChun.toYmd();
|
||||
String liChunYmdHms = liChun.toYmdHms();
|
||||
string liChunYmd = liChun.toYmd();
|
||||
string liChunYmdHms = liChun.toYmdHms();
|
||||
|
||||
//阳历和阴历年份相同代表正月初一及以后
|
||||
if (year == solarYear)
|
||||
@@ -340,8 +340,8 @@ namespace com.nlf.calendar
|
||||
{
|
||||
Solar start = null;
|
||||
Solar end;
|
||||
String ymd = solar.toYmd();
|
||||
String time = solar.toYmdHms();
|
||||
string ymd = solar.toYmd();
|
||||
string time = solar.toYmdHms();
|
||||
int size = JIE_QI_IN_USE.Length;
|
||||
|
||||
//序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0
|
||||
@@ -349,7 +349,7 @@ namespace com.nlf.calendar
|
||||
for (int i = 0; i < size; i += 2)
|
||||
{
|
||||
end = jieQi[JIE_QI_IN_USE[i]];
|
||||
String symd = null == start ? ymd : start.toYmd();
|
||||
string symd = null == start ? ymd : start.toYmd();
|
||||
if (ymd.CompareTo(symd) >= 0 && ymd.CompareTo(end.toYmd()) < 0)
|
||||
{
|
||||
break;
|
||||
@@ -368,7 +368,7 @@ namespace com.nlf.calendar
|
||||
for (int i = 0; i < size; i += 2)
|
||||
{
|
||||
end = jieQi[JIE_QI_IN_USE[i]];
|
||||
String stime = null == start ? time : start.toYmdHms();
|
||||
string stime = null == start ? time : start.toYmdHms();
|
||||
if (time.CompareTo(stime) >= 0 && time.CompareTo(end.toYmdHms()) < 0)
|
||||
{
|
||||
break;
|
||||
@@ -401,7 +401,7 @@ namespace com.nlf.calendar
|
||||
dayZhiIndexExact2 = dayZhiExact;
|
||||
|
||||
// 八字流派1,晚子时(夜子/子夜)日柱算明天
|
||||
String hm = (hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute;
|
||||
string hm = (hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute;
|
||||
if (hm.CompareTo("23:00") >= 0 && hm.CompareTo("23:59") <= 0)
|
||||
{
|
||||
dayGanExact++;
|
||||
@@ -849,10 +849,10 @@ namespace com.nlf.calendar
|
||||
/// <returns>节</returns>
|
||||
public string getJie()
|
||||
{
|
||||
String jie = "";
|
||||
string jie = "";
|
||||
for (int i = 1, j = JIE_QI.Length; i < j; i += 2)
|
||||
{
|
||||
String key = JIE_QI[i];
|
||||
string key = JIE_QI[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
@@ -869,10 +869,10 @@ namespace com.nlf.calendar
|
||||
/// <returns>气</returns>
|
||||
public string getQi()
|
||||
{
|
||||
String qi = "";
|
||||
string qi = "";
|
||||
for (int i = 0, j = JIE_QI.Length; i < j; i += 2)
|
||||
{
|
||||
String key = JIE_QI[i];
|
||||
string key = JIE_QI[i];
|
||||
Solar d = jieQi[key];
|
||||
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay())
|
||||
{
|
||||
@@ -1840,7 +1840,7 @@ namespace com.nlf.calendar
|
||||
public JieQi getNextJie()
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
String[] conditions = new String[l];
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2];
|
||||
@@ -1855,7 +1855,7 @@ namespace com.nlf.calendar
|
||||
public JieQi getPrevJie()
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
String[] conditions = new String[l];
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2];
|
||||
@@ -1870,7 +1870,7 @@ namespace com.nlf.calendar
|
||||
public JieQi getNextQi()
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
String[] conditions = new String[l];
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
|
||||
@@ -1885,7 +1885,7 @@ namespace com.nlf.calendar
|
||||
public JieQi getPrevQi()
|
||||
{
|
||||
int l = JIE_QI_IN_USE.Length / 2;
|
||||
String[] conditions = new String[l];
|
||||
string[] conditions = new string[l];
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
|
||||
@@ -2607,5 +2607,50 @@ namespace com.nlf.calendar
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.Length];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日禄
|
||||
/// </summary>
|
||||
/// <returns>日禄</returns>
|
||||
public string getDayLu()
|
||||
{
|
||||
string gan = LunarUtil.LU[getDayGan()];
|
||||
string zhi = null;
|
||||
try
|
||||
{
|
||||
zhi = LunarUtil.LU[getDayZhi()];
|
||||
}
|
||||
catch { }
|
||||
string lu = gan + "命互禄";
|
||||
if (null != zhi)
|
||||
{
|
||||
lu += " " + zhi + "命进禄";
|
||||
}
|
||||
return lu;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰
|
||||
/// </summary>
|
||||
/// <returns>时辰</returns>
|
||||
public LunarTime getTime()
|
||||
{
|
||||
return new LunarTime(year, month, day, hour, minute, second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当天的时辰列表
|
||||
/// </summary>
|
||||
/// <returns>时辰列表</returns>
|
||||
public List<LunarTime> getTimes()
|
||||
{
|
||||
List<LunarTime> l = new List<LunarTime>();
|
||||
l.Add(new LunarTime(year, month, day, 0, 0, 0));
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
l.Add(new LunarTime(year, month, day, (i + 1) * 2 - 1, 0, 0));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
423
lunar/LunarTime.cs
Normal file
423
lunar/LunarTime.cs
Normal file
@@ -0,0 +1,423 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using com.nlf.calendar.util;
|
||||
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
/// <summary>
|
||||
/// 时辰
|
||||
/// </summary>
|
||||
public class LunarTime
|
||||
{
|
||||
/// <summary>
|
||||
/// 天干下标,0-9
|
||||
/// </summary>
|
||||
private int ganIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 地支下标,0-11
|
||||
/// </summary>
|
||||
private int zhiIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 阴历
|
||||
/// </summary>
|
||||
private Lunar lunar;
|
||||
|
||||
/// <summary>
|
||||
/// 通过农历年月日时初始化
|
||||
/// </summary>
|
||||
/// <param name="lunarYear">年(农历)</param>
|
||||
/// <param name="lunarMonth">月(农历),1到12,闰月为负,即闰2月=-2</param>
|
||||
/// <param name="lunarDay">日(农历),1到31</param>
|
||||
/// <param name="hour">小时(阳历)</param>
|
||||
/// <param name="minute">分钟(阳历)</param>
|
||||
/// <param name="second">秒钟(阳历)</param>
|
||||
public LunarTime(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second)
|
||||
{
|
||||
this.lunar = Lunar.fromYmdHms(lunarYear, lunarMonth, lunarDay, hour, minute, second);
|
||||
this.zhiIndex = LunarUtil.getTimeZhiIndex((hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute);
|
||||
this.ganIndex = (lunar.getDayGanIndexExact() % 5 * 2 + zhiIndex) % 10;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过指定农历年月日获取时辰
|
||||
/// </summary>
|
||||
/// <param name="lunarYear">年(农历)</param>
|
||||
/// <param name="lunarMonth">月(农历),1到12,闰月为负,即闰2月=-2</param>
|
||||
/// <param name="lunarDay">日(农历),1到31</param>
|
||||
/// <param name="hour">小时(阳历)</param>
|
||||
/// <param name="minute">分钟(阳历)</param>
|
||||
/// <param name="second">秒钟(阳历)</param>
|
||||
/// <returns>时辰</returns>
|
||||
public static LunarTime fromYmdHms(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second)
|
||||
{
|
||||
return new LunarTime(lunarYear, lunarMonth, lunarDay, hour, minute, second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰生肖
|
||||
/// </summary>
|
||||
/// <returns>时辰生肖,如虎</returns>
|
||||
public string getShengXiao()
|
||||
{
|
||||
return LunarUtil.SHENGXIAO[zhiIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰(地支)
|
||||
/// </summary>
|
||||
/// <returns>时辰(地支)</returns>
|
||||
public string getZhi()
|
||||
{
|
||||
return LunarUtil.ZHI[zhiIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰(天干)
|
||||
/// </summary>
|
||||
/// <returns>时辰(天干)</returns>
|
||||
public string getGan()
|
||||
{
|
||||
return LunarUtil.GAN[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰干支(时柱)
|
||||
/// </summary>
|
||||
/// <returns>时辰干支(时柱)</returns>
|
||||
public string getGanZhi()
|
||||
{
|
||||
return getGan() + getZhi();
|
||||
}
|
||||
|
||||
/// <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()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰阴贵神方位
|
||||
/// </summary>
|
||||
/// <returns>阴贵神方位,如艮</returns>
|
||||
public string getPositionYinGui()
|
||||
{
|
||||
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰阴贵神方位描述
|
||||
/// </summary>
|
||||
/// <returns>阴贵神方位描述,如东北</returns>
|
||||
public string getPositionYinGuiDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionYinGui()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰福神方位
|
||||
/// </summary>
|
||||
/// <returns>福神方位,如艮</returns>
|
||||
public string getPositionFu()
|
||||
{
|
||||
return LunarUtil.POSITION_FU[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰福神方位描述
|
||||
/// </summary>
|
||||
/// <returns>福神方位描述,如东北</returns>
|
||||
public string getPositionFuDesc()
|
||||
{
|
||||
return LunarUtil.POSITION_DESC[getPositionFu()];
|
||||
}
|
||||
|
||||
/// <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 getChong()
|
||||
{
|
||||
return LunarUtil.CHONG[zhiIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取无情之克的时冲天干
|
||||
/// </summary>
|
||||
/// <returns>无情之克的时冲天干,如甲</returns>
|
||||
public string getChongGan()
|
||||
{
|
||||
return LunarUtil.CHONG_GAN[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取有情之克的时冲天干
|
||||
/// </summary>
|
||||
/// <returns>有情之克的时冲天干,如甲</returns>
|
||||
public string getChongGanTie()
|
||||
{
|
||||
return LunarUtil.CHONG_GAN_TIE[ganIndex + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时冲生肖
|
||||
/// </summary>
|
||||
/// <returns>时冲生肖,如猴</returns>
|
||||
public string getChongShengXiao()
|
||||
{
|
||||
string chong = getChong();
|
||||
for (int i = 0, j = LunarUtil.ZHI.Length; i < j; i++)
|
||||
{
|
||||
if (LunarUtil.ZHI[i].Equals(chong))
|
||||
{
|
||||
return LunarUtil.SHENGXIAO[i];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时冲描述
|
||||
/// </summary>
|
||||
/// <returns>时冲描述,如(壬申)猴</returns>
|
||||
public string getChongDesc()
|
||||
{
|
||||
return "(" + getChongGan() + getChong() + ")" + getChongShengXiao();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时煞
|
||||
/// </summary>
|
||||
/// <returns>时煞,如北</returns>
|
||||
public string getSha()
|
||||
{
|
||||
return LunarUtil.SHA[getZhi()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰纳音
|
||||
/// </summary>
|
||||
/// <returns>时辰纳音,如剑锋金</returns>
|
||||
public string getNaYin()
|
||||
{
|
||||
return LunarUtil.NAYIN[getGanZhi()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值时天神
|
||||
/// </summary>
|
||||
/// <returns>值时天神</returns>
|
||||
public string getTianShen()
|
||||
{
|
||||
string dayZhi = lunar.getDayZhiExact();
|
||||
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET[dayZhi];
|
||||
return LunarUtil.TIAN_SHEN[(zhiIndex + offset) % 12 + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值时天神类型:黄道/黑道
|
||||
/// </summary>
|
||||
/// <returns>值时天神类型:黄道/黑道</returns>
|
||||
public string getTianShenType()
|
||||
{
|
||||
return LunarUtil.TIAN_SHEN_TYPE[getTianShen()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值时天神吉凶
|
||||
/// </summary>
|
||||
/// <returns>吉/凶</returns>
|
||||
public string getTianShenLuck()
|
||||
{
|
||||
return LunarUtil.TIAN_SHEN_TYPE_LUCK[getTianShenType()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰宜,如果没有,返回["无"]
|
||||
/// </summary>
|
||||
/// <returns>宜</returns>
|
||||
public List<string> getYi()
|
||||
{
|
||||
return LunarUtil.getTimeYi(lunar.getDayInGanZhiExact(), getGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰忌,如果没有,返回["无"]
|
||||
/// </summary>
|
||||
/// <returns>忌</returns>
|
||||
public List<string> getJi()
|
||||
{
|
||||
return LunarUtil.getTimeJi(lunar.getDayInGanZhiExact(), getGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。)
|
||||
/// </summary>
|
||||
/// <returns>值时九星</returns>
|
||||
public NineStar getNineStar()
|
||||
{
|
||||
//顺逆
|
||||
string solarYmd = lunar.getSolar().toYmd();
|
||||
Dictionary<string,Solar> jieQi = lunar.getJieQiTable();
|
||||
bool asc = false;
|
||||
if (solarYmd.CompareTo(jieQi["冬至"].toYmd()) >= 0 && solarYmd.CompareTo(jieQi["夏至"].toYmd()) < 0)
|
||||
{
|
||||
asc = true;
|
||||
}
|
||||
int start = asc ? 7 : 3;
|
||||
string dayZhi = lunar.getDayZhi();
|
||||
if ("子午卯酉".Contains(dayZhi))
|
||||
{
|
||||
start = asc ? 1 : 9;
|
||||
}
|
||||
else if ("辰戌丑未".Contains(dayZhi))
|
||||
{
|
||||
start = asc ? 4 : 6;
|
||||
}
|
||||
int index = asc ? start + zhiIndex - 1 : start - zhiIndex - 1;
|
||||
if (index > 8)
|
||||
{
|
||||
index -= 9;
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
index += 9;
|
||||
}
|
||||
return new NineStar(index);
|
||||
}
|
||||
|
||||
public string toString()
|
||||
{
|
||||
return getGanZhi();
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
public int getGanIndex()
|
||||
{
|
||||
return ganIndex;
|
||||
}
|
||||
|
||||
public int getZhiIndex()
|
||||
{
|
||||
return zhiIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时辰所在旬
|
||||
/// </summary>
|
||||
/// <returns>旬</returns>
|
||||
public string getXun()
|
||||
{
|
||||
return LunarUtil.getXun(getGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值时空亡
|
||||
/// </summary>
|
||||
/// <returns>空亡(旬空)</returns>
|
||||
public string getXunKong()
|
||||
{
|
||||
return LunarUtil.getXunKong(getGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前时辰的最早时分
|
||||
/// </summary>
|
||||
/// <returns>时分,如:21:00</returns>
|
||||
public string getMinHm()
|
||||
{
|
||||
int hour = lunar.getHour();
|
||||
if (hour < 1)
|
||||
{
|
||||
return "00:00";
|
||||
}
|
||||
else if (hour > 22)
|
||||
{
|
||||
return "23:00";
|
||||
}
|
||||
if (hour % 2 == 0)
|
||||
{
|
||||
hour -= 1;
|
||||
}
|
||||
return (hour < 10 ? "0" : "") + hour + ":00";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前时辰的最晚时分
|
||||
/// </summary>
|
||||
/// <returns>时分,如:22:59</returns>
|
||||
public string getMaxHm()
|
||||
{
|
||||
int hour = lunar.getHour();
|
||||
if (hour < 1)
|
||||
{
|
||||
return "00:59";
|
||||
}
|
||||
else if (hour > 22)
|
||||
{
|
||||
return "23:59";
|
||||
}
|
||||
if (hour % 2 != 0)
|
||||
{
|
||||
hour += 1;
|
||||
}
|
||||
return (hour < 10 ? "0" : "") + hour + ":59";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -235,5 +235,61 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return year + "年";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取治水(正月第一个辰日是初几,就是几龙治水)
|
||||
/// </summary>
|
||||
/// <returns>治水,如:二龙治水</returns>
|
||||
public string getZhiShui()
|
||||
{
|
||||
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();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 10;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "人分饼";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取耕田(正月第一个丑日是初几,就是几牛耕田)
|
||||
/// </summary>
|
||||
/// <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] + "牛耕田";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取得金(正月第一个辛日是初几,就是几日得金)
|
||||
/// </summary>
|
||||
/// <returns>得金,如:一日得金</returns>
|
||||
public string getDeJin()
|
||||
{
|
||||
int offset = 7 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
|
||||
if (offset < 0)
|
||||
{
|
||||
offset += 10;
|
||||
}
|
||||
return LunarUtil.NUMBER[offset + 1] + "日得金";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("6tail")]
|
||||
[assembly: AssemblyProduct("lunar")]
|
||||
[assembly: AssemblyCopyright("版权所有 (C) 2021")]
|
||||
[assembly: AssemblyCopyright("版权所有 (C) 2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
[assembly: AssemblyVersion("1.2.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.5.0")]
|
||||
[assembly: AssemblyVersion("1.2.6.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.6.0")]
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace com.nlf.calendar
|
||||
}
|
||||
int startYear = today.getYear() - offsetYear;
|
||||
int hour = 0;
|
||||
String timeZhi = timeGanZhi.Substring(1);
|
||||
string timeZhi = timeGanZhi.Substring(1);
|
||||
for (int i = 0, j = LunarUtil.ZHI.Length; i < j; i++)
|
||||
{
|
||||
if (LunarUtil.ZHI[i].Equals(timeZhi))
|
||||
@@ -307,7 +307,7 @@ namespace com.nlf.calendar
|
||||
while (counter < 61)
|
||||
{
|
||||
lunar = solar.getLunar();
|
||||
String dgz = (2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
|
||||
string dgz = (2 == sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
|
||||
if (lunar.getYearInGanZhiExact().Equals(yearGanZhi) && lunar.getMonthInGanZhiExact().Equals(monthGanZhi) && dgz.Equals(dayGanZhi) && lunar.getTimeInGanZhi().Equals(timeGanZhi))
|
||||
{
|
||||
l.Add(solar);
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<Compile Include="util\ShouXingUtil.cs" />
|
||||
<Compile Include="LunarYear.cs" />
|
||||
<Compile Include="LunarMonth.cs" />
|
||||
<Compile Include="LunarTime.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace com.nlf.calendar.util
|
||||
/// <summary>
|
||||
/// 数字
|
||||
/// </summary>
|
||||
public static readonly string[] NUMBER = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
|
||||
public static readonly string[] NUMBER = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
|
||||
|
||||
/// <summary>
|
||||
/// 月
|
||||
@@ -188,6 +188,11 @@ namespace com.nlf.calendar.util
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, string> TIAN_SHEN_TYPE = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// 禄(甲禄在寅,乙禄在卯,丙戊禄在巳、丁己禄在午、庚禄在申、辛禄在酉、壬禄在亥、癸禄在子)
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, string> LU = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// 天神类型吉凶
|
||||
/// </summary>
|
||||
@@ -313,6 +318,26 @@ namespace com.nlf.calendar.util
|
||||
TIAN_SHEN_TYPE_LUCK.Add("黄道", "吉");
|
||||
TIAN_SHEN_TYPE_LUCK.Add("黑道", "凶");
|
||||
|
||||
LU.Add("甲", "寅");
|
||||
LU.Add("乙", "卯");
|
||||
LU.Add("丙", "巳");
|
||||
LU.Add("丁", "午");
|
||||
LU.Add("戊", "巳");
|
||||
LU.Add("己", "午");
|
||||
LU.Add("庚", "申");
|
||||
LU.Add("辛", "酉");
|
||||
LU.Add("壬", "亥");
|
||||
LU.Add("癸", "子");
|
||||
|
||||
LU.Add("寅", "甲");
|
||||
LU.Add("卯", "乙");
|
||||
LU.Add("巳", "丙,戊");
|
||||
LU.Add("午", "丁,己");
|
||||
LU.Add("申", "庚");
|
||||
LU.Add("酉", "辛");
|
||||
LU.Add("亥", "壬");
|
||||
LU.Add("子", "癸");
|
||||
|
||||
FESTIVAL.Add("1-1", "春节");
|
||||
FESTIVAL.Add("1-15", "元宵节");
|
||||
FESTIVAL.Add("2-2", "龙头节");
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -303,8 +303,8 @@ namespace test
|
||||
[TestMethod()]
|
||||
public void test12()
|
||||
{
|
||||
Solar solar = Solar.fromYmdHms(1500, 12, 31, 12, 0, 0);
|
||||
Assert.AreEqual("一五〇〇年腊月十一", solar.getLunar().toString());
|
||||
// Solar solar = Solar.fromYmdHms(1500, 12, 31, 12, 0, 0);
|
||||
// Assert.AreEqual("一五〇〇年腊月十一", solar.getLunar().toString());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
@@ -507,6 +507,22 @@ namespace test
|
||||
Assert.AreEqual("丙寅", lunar.getDayInGanZhi());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test45()
|
||||
{
|
||||
Solar solar = Solar.fromYmd(2017, 2, 15);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("子命互禄 辛命进禄", lunar.getDayLu());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test46()
|
||||
{
|
||||
Solar solar = Solar.fromYmd(2017, 2, 16);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.AreEqual("寅命互禄", lunar.getDayLu());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
108
test/YearTest.cs
Normal file
108
test/YearTest.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using com.nlf.calendar;
|
||||
using com.nlf.calendar.util;
|
||||
namespace test
|
||||
{
|
||||
|
||||
[TestClass()]
|
||||
public class YearTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///获取或设置测试上下文,上下文提供
|
||||
///有关当前测试运行及其功能的信息。
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#region 附加测试属性
|
||||
//
|
||||
//编写测试时,可使用以下附加属性:
|
||||
//
|
||||
//使用 ClassInitialize 在运行类中的第一个测试前先运行代码
|
||||
//
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 ClassCleanup 在运行完类中的所有测试后再运行代码
|
||||
//
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestInitialize 在运行每个测试前先运行代码
|
||||
//
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestCleanup 在运行完每个测试后运行代码
|
||||
//
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
[TestMethod()]
|
||||
public void test1()
|
||||
{
|
||||
LunarYear year = new LunarYear(2017);
|
||||
Assert.AreEqual("二龙治水", year.getZhiShui());
|
||||
Assert.AreEqual("二人分饼", year.getFenBing());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test2()
|
||||
{
|
||||
LunarYear year = new LunarYear(2018);
|
||||
Assert.AreEqual("二龙治水", year.getZhiShui());
|
||||
Assert.AreEqual("八人分饼", year.getFenBing());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test3()
|
||||
{
|
||||
LunarYear year = new LunarYear(5);
|
||||
Assert.AreEqual("三龙治水", year.getZhiShui());
|
||||
Assert.AreEqual("一人分饼", year.getFenBing());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test4()
|
||||
{
|
||||
LunarYear year = new LunarYear(2021);
|
||||
Assert.AreEqual("十一牛耕田", year.getGengTian());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test5()
|
||||
{
|
||||
LunarYear year = new LunarYear(2018);
|
||||
Assert.AreEqual("三日得金", year.getDeJin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -52,6 +52,7 @@
|
||||
<Compile Include="WuHouTest.cs" />
|
||||
<Compile Include="LunarTest.cs" />
|
||||
<Compile Include="YunTest.cs" />
|
||||
<Compile Include="YearTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AuthoringTests.txt" />
|
||||
|
||||
Reference in New Issue
Block a user