public static ImmutablePeriodOfTime AddDays(ImmutablePeriodOfTime period, int days) { return(new ImmutablePeriodOfTime( period.InitialDate.AddDays(days), period.FinalDate.AddDays(days) )); }
static void Main(string[] args) { ImmutablePeriodOfTime period = new ImmutablePeriodOfTime( DateTime.Parse("20/08/2016"), DateTime.Parse("31/08/2016") ); DateTime[] dates = new DateTime[] { DateTime.Parse("18/08/2019"), DateTime.Parse("22/08/2016"), DateTime.Parse("01/09/2019") }; foreach (DateTime date in dates) { bool result = ImmutablePeriodOfTime.CheckIfDateIsBetweenThePeriod(period, date); Console.WriteLine(result); } ImmutablePeriodOfTime.AddDays(period, 30); foreach (DateTime date in dates) { bool result = ImmutablePeriodOfTime.CheckIfDateIsBetweenThePeriod(period, date); Console.WriteLine(result); } }
public static bool CheckIfDateIsBetweenThePeriod(ImmutablePeriodOfTime period, DateTime date) { return(date.CompareTo(period.InitialDate) >= 0 && date.CompareTo(period.FinalDate) <= 0); }