// THIS FILE IS PART OF ChineseCalendar PROJECT
// THE ChineseCalendar PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
// COPYRIGHT (C) lpz. ALL RIGHTS RESERVED.
// GITEE: https://gitee.com/lipz89/ChineseCalendar
using System;
namespace ChineseCalendar
{
///
/// 固定公历日期节假日
///
public class FixDateFestival : Festival
{
/// 节日的第一个日期
public DateTime? First { get; protected set; }
/// 年份
public int Year { get; private set; }
/// 日期
public DateTime Date { get; private set; }
///
/// 定义一个固定公历日期节假日
///
/// 节日名称
/// 年份
/// 月份
/// 日期
/// 节日描述
/// 没有名称
/// 年月日超出范围
public FixDateFestival(string name, int year, int month, int day, string description = null)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name));
}
try
{
this.Name = name;
this.Year = year;
this.Month = month;
this.Day = day;
this.Description = description;
this.First = this.Date = new DateTime(year, month, day);
}
catch (Exception ex)
{
throw new ArgumentOutOfRangeException("日期参数不正确", ex);
}
}
///
/// 定义一个固定公历日期节假日
///
/// 节日名称
/// 节日的公历日期
/// 节日描述
/// 没有名称
public FixDateFestival(string name, DateTime date, string description = null)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name));
}
this.Name = name;
this.Year = date.Year;
this.Month = date.Month;
this.Day = date.Day;
this.Description = description;
this.Date = date;
}
///
public override DateTime? GetLastDate(DateTime? date, bool containsThisDate = false)
{
DateTime date2 = date.HasValue ? date.Value.Date : DateTime.Today;
if (containsThisDate && IsThisFestival(date2))
{
return date2;
}
if (this.Date < date2)
{
return this.Date;
}
return null;
}
///
public override DateTime? GetNextDate(DateTime? date, bool containsThisDate = false)
{
DateTime date2 = date.HasValue ? date.Value.Date : DateTime.Today;
if (containsThisDate && IsThisFestival(date2))
{
return date2;
}
if (this.Date > date2)
{
return this.Date;
}
return null;
}
///
public override bool IsThisFestival(DateTime date)
{
return date.Date == Date.Date;
}
}
}