public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { var d = (DateInfo)value; ChineseAlmanac ca = new ChineseAlmanac(); string holiday = ""; if (HolidayHelper.Instance.HolidayInfo?.ChineseHolidays != null) { holiday = ca.GetChineseHoliday(d.DateTime, HolidayHelper.Instance.HolidayInfo.ChineseHolidays); } if (holiday != "") { return(holiday); } if (HolidayHelper.Instance.HolidayInfo?.Holidays != null) { holiday = ca.GetHoliday(d.DateTime, HolidayHelper.Instance.HolidayInfo.Holidays); } return(holiday); } catch (Exception) { return(""); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var d = value as DateInfo; if (d == null) { return(""); } GregorianCalendar gc = new GregorianCalendar(); ChineseAlmanac ca = new ChineseAlmanac(); var jieqi = d.OB.Ljq; var sanfu = ca.GetSanFuInfo(d.DateTime); var shujiu = ca.GetShuJiuInfo(d.DateTime); string holiday = ""; string chineseHoliday = ""; if (HolidayHelper.Instance.HolidayInfo?.ChineseHolidays != null) { holiday = ca.GetChineseHoliday(d.DateTime, HolidayHelper.Instance.HolidayInfo.ChineseHolidays); } if (HolidayHelper.Instance.HolidayInfo?.Holidays != null) { chineseHoliday = ca.GetHoliday(d.DateTime, HolidayHelper.Instance.HolidayInfo.Holidays); } var result = $"第{d.DateTime.DayOfYear}天 第{gc.GetWeekOfYear(d.DateTime, CalendarWeekRule.FirstDay, DayOfWeek.Monday)}周"; var info = ""; if (jieqi != "") { info += jieqi; } if (sanfu != "") { info += info == "" ? sanfu : " " + sanfu; } if (shujiu != "") { info += info == "" ? shujiu : " " + shujiu; } if (holiday != "") { info += info == "" ? holiday : " " + holiday; } if (chineseHoliday != "") { info += info == "" ? chineseHoliday : " " + chineseHoliday; } result += $"{(info == "" ? "" : $" ({info})")}";