v1.2.19.0 新增525心理健康节;修复出现多个全国中小学生安全教育日的问题;新增胎息;修复部分胎元错误;节假日数据支持删除。

This commit is contained in:
6tail
2022-05-24 21:16:33 +08:00
parent f8eb11f707
commit 986612c329
11 changed files with 120 additions and 49 deletions

View File

@@ -313,6 +313,18 @@ namespace com.nlf.calendar
return LunarUtil.NAYIN[getTaiYuan()];
}
public string getTaiXi()
{
int ganIndex = 2 == sect ? lunar.getDayGanIndexExact2() : lunar.getDayGanIndexExact();
int zhiIndex = 2 == sect ? lunar.getDayZhiIndexExact2() : lunar.getDayZhiIndexExact();
return LunarUtil.HE_GAN_5[ganIndex] + LunarUtil.HE_ZHI_6[zhiIndex];
}
public string getTaiXiNaYin()
{
return LunarUtil.NAYIN[getTaiXi()];
}
public string getMingGong()
{
int monthZhiIndex = 0;
@@ -367,7 +379,11 @@ namespace com.nlf.calendar
timeZhiIndex = i;
}
}
int zhiIndex = (2 + (monthZhiIndex + timeZhiIndex)) % 12;
int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
if (zhiIndex > 12)
{
zhiIndex -= 12;
}
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
if (jiaZiIndex >= 60)
{

View File

@@ -1551,7 +1551,7 @@ namespace com.nlf.calendar
/// <returns>日冲,如申</returns>
public string getDayChong()
{
return LunarUtil.CHONG[dayZhiIndex + 1];
return LunarUtil.CHONG[dayZhiIndex];
}
/// <summary>
@@ -1560,7 +1560,7 @@ namespace com.nlf.calendar
/// <returns>时冲,如申</returns>
public string getTimeChong()
{
return LunarUtil.CHONG[timeZhiIndex + 1];
return LunarUtil.CHONG[timeZhiIndex];
}
[Obsolete("This method is obsolete, use method getDayChongGan instead")]
@@ -1575,7 +1575,7 @@ namespace com.nlf.calendar
/// <returns>无情之克的日冲天干,如甲</returns>
public string getDayChongGan()
{
return LunarUtil.CHONG_GAN[dayGanIndex + 1];
return LunarUtil.CHONG_GAN[dayGanIndex];
}
/// <summary>
@@ -1584,7 +1584,7 @@ namespace com.nlf.calendar
/// <returns>无情之克的时冲天干,如甲</returns>
public string getTimeChongGan()
{
return LunarUtil.CHONG_GAN[timeGanIndex + 1];
return LunarUtil.CHONG_GAN[timeGanIndex];
}
[Obsolete("This method is obsolete, use method getDayChongGanTie instead")]
@@ -1599,7 +1599,7 @@ namespace com.nlf.calendar
/// <returns>有情之克的日冲天干,如甲</returns>
public string getDayChongGanTie()
{
return LunarUtil.CHONG_GAN_TIE[dayGanIndex + 1];
return LunarUtil.CHONG_GAN_TIE[dayGanIndex];
}
/// <summary>
@@ -1608,7 +1608,7 @@ namespace com.nlf.calendar
/// <returns>有情之克的时冲天干,如甲</returns>
public string getTimeChongGanTie()
{
return LunarUtil.CHONG_GAN_TIE[timeGanIndex + 1];
return LunarUtil.CHONG_GAN_TIE[timeGanIndex];
}
[Obsolete("This method is obsolete, use method getDayChongShengXiao instead")]

View File

@@ -208,7 +208,7 @@ namespace com.nlf.calendar
/// <returns>时冲,如申</returns>
public string getChong()
{
return LunarUtil.CHONG[zhiIndex + 1];
return LunarUtil.CHONG[zhiIndex];
}
/// <summary>
@@ -217,7 +217,7 @@ namespace com.nlf.calendar
/// <returns>无情之克的时冲天干,如甲</returns>
public string getChongGan()
{
return LunarUtil.CHONG_GAN[ganIndex + 1];
return LunarUtil.CHONG_GAN[ganIndex];
}
/// <summary>
@@ -226,7 +226,7 @@ namespace com.nlf.calendar
/// <returns>有情之克的时冲天干,如甲</returns>
public string getChongGanTie()
{
return LunarUtil.CHONG_GAN_TIE[ganIndex + 1];
return LunarUtil.CHONG_GAN_TIE[ganIndex];
}
/// <summary>

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("1.2.18.0")]
[assembly: AssemblyFileVersion("1.2.18.0")]
[assembly: AssemblyVersion("1.2.19.0")]
[assembly: AssemblyFileVersion("1.2.19.0")]

View File

@@ -438,7 +438,7 @@ namespace com.nlf.calendar
l.Add(SolarUtil.WEEK_FESTIVAL[month + "-" + weeks + "-" + week]);
}
catch { }
if (day + 7 >= SolarUtil.getDaysOfMonth(year, month))
if (day + 7 > SolarUtil.getDaysOfMonth(year, month))
{
try
{

View File

@@ -7,13 +7,13 @@
<Summary>a calendar library for Solar and Chinese Lunar</Summary>
<PackageTags>日历;公历;阳历;农历;阴历;老黄历;佛历;道历;法定假日</PackageTags>
<Description>日历、公历(阳历)、农历(阴历、老黄历)、佛历、道历,节假日、星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。</Description>
<PackageReleaseNotes>新增万圣节、万圣节前夜;新增全国中小学生安全教育日;新增春社(原二月初二春社改为社日节)、秋社;新增寒食节</PackageReleaseNotes>
<PackageReleaseNotes>新增525心理健康节修复出现多个全国中小学生安全教育日的问题新增胎息修复部分胎元错误节假日数据支持删除</PackageReleaseNotes>
<Copyright>版权所有 (c) 2021</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>http://6tail.cn/calendar/api.html</PackageProjectUrl>
<RepositoryUrl>https://github.com/6tail/lunar-csharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>1.2.18.0</Version>
<Version>1.2.19.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

View File

@@ -19,6 +19,11 @@ namespace com.nlf.calendar.util
/// </summary>
private const char ZERO = '0';
/// <summary>
/// 删除标识
/// </summary>
private const string TAG_REMOVE = "~";
/// <summary>
/// 节假日名称元旦0春节1清明2劳动3端午4中秋5国庆6国庆中秋7抗战胜利日8
/// </summary>
@@ -240,10 +245,14 @@ namespace com.nlf.calendar.util
{
string segment = data.Substring(0, SIZE);
string day = segment.Substring(0, 8);
bool remove = TAG_REMOVE.Equals(segment.Substring(8, 1));
Holiday holiday = getHoliday(day);
if (null == holiday)
{
append.Append(segment);
if (!remove)
{
append.Append(segment);
}
}
else
{
@@ -259,7 +268,7 @@ namespace com.nlf.calendar.util
if (nameIndex > -1)
{
string old = day + (char)(nameIndex + ZERO) + (holiday.isWork() ? ZERO : '1') + holiday.getTarget().Replace("-", "");
DATA_IN_USE = DATA_IN_USE.Replace(old, segment);
DATA_IN_USE = DATA_IN_USE.Replace(old, remove ? "" : segment);
}
}
data = data.Substring(SIZE);

View File

@@ -186,17 +186,32 @@ namespace com.nlf.calendar.util
/// <summary>
/// 地支相冲(子午相冲,丑未相冲,寅申相冲,辰戌相冲,卯酉相冲,巳亥相冲),由于地支对应十二生肖,也就对应了生肖相冲
/// </summary>
public static readonly string[] CHONG = { "", "午", "未", "申", "酉", "戌", "亥", "子", "丑", "寅", "卯", "辰", "巳" };
public static readonly string[] CHONG = { "午", "未", "申", "酉", "戌", "亥", "子", "丑", "寅", "卯", "辰", "巳" };
/// <summary>
/// 天干相冲之无情之克(阳克阳,阴克阴)
/// </summary>
public static readonly string[] CHONG_GAN = { "", "戊", "己", "庚", "辛", "壬", "癸", "甲", "乙", "丙", "丁" };
public static readonly string[] CHONG_GAN = { "戊", "己", "庚", "辛", "壬", "癸", "甲", "乙", "丙", "丁" };
/// <summary>
/// 天干相冲之有情之克(阳克阴,阴克阳)
/// </summary>
public static readonly string[] CHONG_GAN_TIE = { "", "己", "戊", "辛", "庚", "癸", "壬", "乙", "甲", "丁", "丙" };
public static readonly string[] CHONG_GAN_TIE = { "己", "戊", "辛", "庚", "癸", "壬", "乙", "甲", "丁", "丙" };
/// <summary>
/// 天干四冲
/// </summary>
public static readonly string[] CHONG_GAN_4 = { "庚", "辛", "壬", "癸", "", "", "甲", "乙", "丙", "丁" };
/// <summary>
/// 天干五合
/// </summary>
public static readonly string[] HE_GAN_5 = { "己", "庚", "辛", "壬", "癸", "甲", "乙", "丙", "丁", "戊" };
/// <summary>
/// 地支六合
/// </summary>
public static readonly string[] HE_ZHI_6 = { "丑", "子", "亥", "戌", "酉", "申", "未", "午", "巳", "辰", "卯", "寅" };
/// <summary>
/// 月份地支对应天神偏移下标
@@ -241,16 +256,6 @@ namespace com.nlf.calendar.util
/// </summary>
public static readonly Dictionary<string, string> SHOU = new Dictionary<string, string>();
/// <summary>
/// 天干四冲无情之克中克得最严重的4个
/// </summary>
public static readonly Dictionary<string, string> CHONG_GAN_BAD = new Dictionary<string, string>();
/// <summary>
/// 天干五合有情之克中最有情的5个
/// </summary>
public static readonly Dictionary<string, string> CHONG_GAN_TIE_GOOD = new Dictionary<string, string>();
/// <summary>
/// 煞
/// </summary>
@@ -554,17 +559,6 @@ namespace com.nlf.calendar.util
SHOU.Add("西", "白虎");
SHOU.Add("北", "玄武");
CHONG_GAN_BAD.Add("庚", "甲");
CHONG_GAN_BAD.Add("辛", "乙");
CHONG_GAN_BAD.Add("壬", "丙");
CHONG_GAN_BAD.Add("癸", "丁");
CHONG_GAN_TIE_GOOD.Add("甲", "己");
CHONG_GAN_TIE_GOOD.Add("丙", "辛");
CHONG_GAN_TIE_GOOD.Add("戊", "癸");
CHONG_GAN_TIE_GOOD.Add("庚", "乙");
CHONG_GAN_TIE_GOOD.Add("壬", "丁");
SHA.Add("子", "南");
SHA.Add("丑", "东");
SHA.Add("寅", "北");

View File

@@ -85,6 +85,7 @@ namespace com.nlf.calendar.util
OTHER_FESTIVAL.Add("5-5", new List<string>(new string[] { "马克思诞辰纪念日" }));
OTHER_FESTIVAL.Add("5-8", new List<string>(new string[] { "世界红十字日" }));
OTHER_FESTIVAL.Add("5-11", new List<string>(new string[] { "世界肥胖日" }));
OTHER_FESTIVAL.Add("5-25", new List<string>(new string[] { "525心理健康节" }));
OTHER_FESTIVAL.Add("5-27", new List<string>(new string[] { "上海解放日" }));
OTHER_FESTIVAL.Add("5-31", new List<string>(new string[] { "世界无烟日" }));
OTHER_FESTIVAL.Add("6-5", new List<string>(new string[] { "世界环境日" }));

View File

@@ -303,5 +303,45 @@ namespace test
Assert.AreEqual("1995-11-05", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
}
[TestMethod()]
public void testShenGong()
{
Solar solar = new Solar(1995, 12, 18, 10, 28, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.AreEqual("壬午", eightChar.getShenGong());
}
[TestMethod()]
public void testShenGong1()
{
Solar solar = new Solar(1994, 12, 6, 2, 0, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.AreEqual("丁丑", eightChar.getShenGong());
}
[TestMethod()]
public void testShenGong2()
{
Solar solar = new Solar(1990, 12, 11, 6, 0, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.AreEqual("庚辰", eightChar.getShenGong());
}
[TestMethod()]
public void testShenGong3()
{
Solar solar = new Solar(1993, 5, 23, 4, 0, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Assert.AreEqual("庚申", eightChar.getShenGong());
}
}
}

View File

@@ -84,7 +84,7 @@ namespace test
string expected = "2020-05-01 劳动节 2020-05-01";
string actual = null;
actual = com.nlf.calendar.util.HolidayUtil.getHoliday(year, month, day).ToString();
actual = HolidayUtil.getHoliday(year, month, day).ToString();
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHoliday 未返回所需的值。");
}
@@ -100,7 +100,7 @@ namespace test
string expected = "2011-05-02 劳动节 2011-05-01";
string actual;
actual = com.nlf.calendar.util.HolidayUtil.getHoliday(ymd).ToString();
actual = HolidayUtil.getHoliday(ymd).ToString();
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHoliday 未返回所需的值。");
}
@@ -116,7 +116,7 @@ namespace test
int expected = 35;
int actual;
actual = com.nlf.calendar.util.HolidayUtil.getHolidays(year).Count;
actual = HolidayUtil.getHolidays(year).Count;
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHolidays 未返回所需的值。");
}
@@ -134,7 +134,7 @@ namespace test
int expected = 1;
int actual;
actual = com.nlf.calendar.util.HolidayUtil.getHolidays(year, month).Count;
actual = HolidayUtil.getHolidays(year, month).Count;
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHolidays 未返回所需的值。");
}
@@ -150,7 +150,7 @@ namespace test
int expected = 35;
int actual;
actual = com.nlf.calendar.util.HolidayUtil.getHolidays(ymd).Count;
actual = HolidayUtil.getHolidays(ymd).Count;
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHolidays 未返回所需的值。");
}
@@ -170,7 +170,7 @@ namespace test
int expected = 4;
int actual;
actual = com.nlf.calendar.util.HolidayUtil.getHolidaysByTarget(year, month, day).Count;
actual = HolidayUtil.getHolidaysByTarget(year, month, day).Count;
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHolidaysByTarget 未返回所需的值。");
}
@@ -186,7 +186,7 @@ namespace test
int expected = 4;
int actual;
actual = com.nlf.calendar.util.HolidayUtil.getHolidaysByTarget(ymd).Count;
actual = HolidayUtil.getHolidaysByTarget(ymd).Count;
Assert.AreEqual(expected, actual, "com.nlf.calendar.util.HolidayUtil.getHolidaysByTarget 未返回所需的值。");
}
@@ -246,10 +246,21 @@ namespace test
string expected = "2016-10-01";
string actual;
actual = com.nlf.calendar.util.HolidayUtil.getHoliday(ymd).getTarget();
actual = HolidayUtil.getHoliday(ymd).getTarget();
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void test6()
{
string ymd = "2010-01-01";
Assert.AreEqual("元旦", HolidayUtil.getHoliday(ymd).getName());
HolidayUtil.fix("20100101~000000000000000000000000000");
Assert.IsNull(HolidayUtil.getHoliday(ymd));
}
}