using System.Collections.Generic;
using System.Text;
using Lunar.Util;
using System;
using System.Linq;
// ReSharper disable InconsistentNaming
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable IdentifierTypo
namespace Lunar
{
///
/// 道历
///
public class Tao
{
///
/// 生年
///
public const int BIRTH_YEAR = -2697;
///
/// 阴历
///
private Lunar Lunar { get; }
///
/// 初始化
///
/// 阴历
public Tao(Lunar lunar)
{
Lunar = lunar;
}
///
/// 初始化
///
/// 阴历
/// 道历
public static Tao FromLunar(Lunar lunar)
{
return new Tao(lunar);
}
///
/// 初始化
///
/// 阴历年
/// 阴历月
/// 阴历日
/// 小时
/// 分钟
/// 秒钟
/// 道历
public static Tao FromYmdHms(int year, int month, int day, int hour = 0, int minute = 0, int second = 0)
{
return FromLunar(Lunar.FromYmdHms(year + BIRTH_YEAR, month, day, hour, minute, second));
}
///
/// 年
///
public int Year => Lunar.Year - BIRTH_YEAR;
///
/// 月
///
public int Month => Lunar.Month;
///
/// 日
///
public int Day => Lunar.Day;
///
/// 中文年
///
public string YearInChinese
{
get
{
var y = (Year + "").ToCharArray();
var s = new StringBuilder();
for (int i = 0, j = y.Length; i < j; i++)
{
s.Append(LunarUtil.NUMBER[y[i] - '0']);
}
return s.ToString();
}
}
///
/// 中文月
///
public string MonthInChinese => Lunar.MonthInChinese;
///
/// 中文日
///
public string DayInChinese => Lunar.DayInChinese;
///
/// 节日
///
public List Festivals
{
get
{
var l = new List();
try
{
l.AddRange(TaoUtil.FESTIVAL[Month + "-" + Day]);
}
catch
{
// ignored
}
var jq = Lunar.JieQi;
switch (jq)
{
case "冬至":
l.Add(new TaoFestival("元始天尊圣诞"));
break;
case "夏至":
l.Add(new TaoFestival("灵宝天尊圣诞"));
break;
}
// 八节日
try
{
l.Add(new TaoFestival(TaoUtil.BA_JIE[jq]));
}
catch
{
// ignored
}
// 八会日
try
{
l.Add(new TaoFestival(TaoUtil.BA_HUI[Lunar.DayInGanZhi]));
}
catch
{
// ignored
}
return l;
}
}
private bool IsDayIn(string[] days)
{
var md = Month + "-" + Day;
return days.Any(d => md.Equals(d));
}
///
/// 是否三会日
///
public bool DaySanHui => IsDayIn(TaoUtil.SAN_HUI);
///
/// 是否三元日
///
public bool DaySanYuan => IsDayIn(TaoUtil.SAN_YUAN);
///
/// 是否五腊日
///
public bool DayWuLa => IsDayIn(TaoUtil.WU_LA);
///
/// 是否八节日
///
public bool DayBaJie => TaoUtil.BA_JIE.ContainsKey(Lunar.JieQi);
///
/// 是否八会日
///
public bool DayBaHui => TaoUtil.BA_HUI.ContainsKey(Lunar.DayInGanZhi);
///
/// 是否明戊日
///
public bool DayMingWu => "戊".Equals(Lunar.DayGan);
///
/// 是否暗戊日
///
public bool DayAnWu => Lunar.DayZhi.Equals(TaoUtil.AN_WU[Math.Abs(Month) - 1]);
///
/// 是否戊日
///
public bool DayWu => DayMingWu || DayAnWu;
///
/// 是否天赦日
///
public bool DayTianShe
{
get
{
var ret = false;
var mz = Lunar.MonthZhi;
var dgz = Lunar.DayInGanZhi;
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 FullString => "道歷" + YearInChinese + "年,天運" + Lunar.YearInGanZhi + "年," + Lunar.MonthInGanZhi + "月," + Lunar.DayInGanZhi + "日。" + MonthInChinese + "月" + DayInChinese + "日," + Lunar.TimeZhi + "時。";
///
public override string ToString()
{
return YearInChinese + "年" + MonthInChinese + "月" + DayInChinese;
}
}
}