using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lunar.Util;
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
// ReSharper disable MemberCanBePrivate.Global
namespace Lunar
{
///
/// 佛历
///
public class Foto
{
///
/// 佛涅磐年
///
public const int DEAD_YEAR = -543;
///
/// 阴历
///
public Lunar Lunar { get; }
///
/// 初始化
///
/// 阴历
public Foto(Lunar lunar)
{
Lunar = lunar;
}
///
/// 初始化
///
/// 阴历
/// 佛历
public static Foto FromLunar(Lunar lunar)
{
return new Foto(lunar);
}
///
/// 初始化
///
/// 阴历年
/// 阴历月
/// 阴历日
/// 小时
/// 分钟
/// 秒钟
/// 佛历
public static Foto FromYmdHms(int lunarYear, int lunarMonth, int lunarDay, int hour = 0, int minute = 0, int second = 0)
{
return FromLunar(Lunar.FromYmdHms(lunarYear + DEAD_YEAR - 1, lunarMonth, lunarDay, hour, minute, second));
}
///
/// 年
///
public int Year
{
get
{
var sy = Lunar.Solar.Year;
var y = sy - DEAD_YEAR;
if (sy == Lunar.Year)
{
y++;
}
return y;
}
}
///
/// 月
///
public int Month => Lunar.Month;
///
/// 日
///
public int Day => Lunar.Day;
///
/// 中文年
///
public string YearInChinese
{
get
{
var y = Year.ToString().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(FotoUtil.FESTIVAL[Math.Abs(Month) + "-" + Day]);
}
catch
{
// ignored
}
return l;
}
}
///
/// 纪念日
///
public List OtherFestivals
{
get
{
var l = new List();
try
{
var fs = FotoUtil.OTHER_FESTIVAL[$"{Month}-{Day}"];
l.AddRange(fs);
}
catch
{
// ignored
}
return l;
}
}
///
/// 月斋
///
public bool MonthZhai => Month == 1 || Month == 5 || Month == 9;
///
/// 杨公忌日
///
public bool DayYangGong
{
get
{
return Festivals.Any(f => "杨公忌".Equals(f.Name));
}
}
///
/// 朔望斋日
///
public bool DayZhaiShuoWang => Day == 1 || Day == 15;
///
/// 六斋日
///
public bool DayZhaiSix
{
get
{
switch (Day)
{
case 8:
case 14:
case 15:
case 23:
case 29:
case 30:
return true;
case 28:
{
var m = LunarMonth.FromYm(Lunar.Year, Month);
return null != m && 30 != m.DayCount;
}
default:
return false;
}
}
}
///
/// 十斋日
///
public bool DayZhaiTen => Day == 1 || Day == 8 || Day == 14 || Day == 15 || Day == 18 || Day == 23 || Day == 24 || Day == 28 || Day == 29 || Day == 30;
///
/// 观音斋日
///
public bool DayZhaiGuanYin
{
get
{
var k = $"{Month}-{Day}";
return FotoUtil.DAY_ZHAI_GUAN_YIN.Any(d => k.Equals(d));
}
}
///
/// 宿
///
public string Xiu => FotoUtil.GetXiu(Month, Day);
///
/// 宿吉凶
///
public string XiuLuck => LunarUtil.XIU_LUCK[Xiu];
///
/// 宿歌诀
///
public string XiuSong => LunarUtil.XIU_SONG[Xiu];
///
/// 政
///
public string Zheng => LunarUtil.ZHENG[Xiu];
///
/// 动物
///
public string Animal => LunarUtil.ANIMAL[Xiu];
///
/// 宫
///
public string Gong => LunarUtil.GONG[Xiu];
///
/// 兽
///
public string Shou => LunarUtil.SHOU[Gong];
///
/// 完整字符串输出
///
public string FullString
{
get
{
var s = new StringBuilder();
s.Append(ToString());
foreach (var f in Festivals)
{
s.Append(" (");
s.Append(f);
s.Append(')');
}
return s.ToString();
}
}
///
public override string ToString()
{
return $"{YearInChinese}年{MonthInChinese}月{DayInChinese}";
}
}
}