We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pattern Question

I am evaluating your product and am seeing unexpected results in one of the configured patterns. I have a pattern that (according to the docs) occurs the last business day of each month starting on Oct 1, 1998 at 12:00 AM. When I get a list of matching dates between Oct 1, 1998 12:00 AM and Oct 31, 1998 12:00 AM it returns two dates: Oct 1, 1998 12:00 AM and 10/30/1998 12:00 AM.

Obviously Oct 1, 1998 does not qualify as the last day of the month, so either my pattern is wrong or there is a bug. Here is the source:

...

RecurrencePattern pattern = new RecurrencePattern();

RecurrenceRule rule = new RecurrenceRule();

rule.Frequency = Frequency.Monthly;

rule.Interval = 1;

rule.BySetPos.Add(-1);

rule.ByDay.Add(DayOfWeek.Monday);

rule.ByDay.Add(DayOfWeek.Tuesday);

rule.ByDay.Add(DayOfWeek.Wednesday);

rule.ByDay.Add(DayOfWeek.Thursday);

rule.ByDay.Add(DayOfWeek.Friday);

rule.EndType = EndType.None;

pattern.StartDate = DateTime.BeginningOfThisMonth;

pattern.RRules.Add(rule);

string patternString = pattern.ToiCalendar();

// Matches for this month

Console.WriteLine(string.Format("Dates between {0} and {1}", DateTime.BeginningOfThisMonth, DateTime.EndOfThisMonth));

Console.WriteLine("-------------------------");

Console.WriteLine(pattern.ToiCalendar());

dates = pattern.GenerateOccurrences(DateTime.BeginningOfThisMonth, DateTime.EndOfThisMonth);

foreach (System.DateTime dt in dates)

{

Console.WriteLine("Date: " + dt.ToString());

}

...

Here is a custom DateTime giving me the BeginningOfThisMonth and EndOfThisMonth. Sorry if this was confusing, but I did this to work with DateTime with an offset for th eval:

public class DateTime

{

private const int evaluationOffset = -10;

public static System.DateTime Now

{

get { return System.DateTime.Now.AddYears(evaluationOffset); }

}

public static System.DateTime BeginningOfThisMonth

{

get { return new System.DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); }

}

public static System.DateTime EndOfThisMonth

{

get { return new System.DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1).AddDays(-1); }

}

}

My apologies ... I completely discounted that the start date is part of the pattern. Since my search range includes the start date, it matches that as well. I'm so embarrassed :)