Hi Dalbir,
Thank you for inquiry.
GenerateOccurrences() method will calculate the dates every time. In your pattern, the start date is in year 2008. In your scenario, you want to find out the next occurrence from specific date/time, could you please try modifying the start and end dates as below, to reduce the number of dates generated. This will also reduce the CPU work and memory storage.
string pattern = @“DTSTART:20081118T072354
RRULE:FREQ=DAILY;UNTIL=20110824T232454Z;BYHOUR=7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
;BYMINUTE=23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22”;
RecurrencePattern recPattern = new RecurrencePattern(pattern);
// This is the specific date, for which you want to find next occurrence
DateTime specificDate = new DateTime(2009, 1, 1, 11, 0, 0);
// Set start date to a day before
DateTime startDate = specificDate.AddDays(-1);
recPattern.StartDate = startDate;
// Modify the rule, sent Until to specific day + 1
recPattern.RRules[0].Until = specificDate.AddDays(1);
I hope it helps.
Thanks for the reply,
Hi,
I have consulted with the development team for their feedback on this issue. I will get back to you as soon as I have some update for you.
Hi Dalbir,
Could you please try the following workaround?
// Original recurrence pattern
string pattern = @“DTSTART:20081118T072354
RRULE:FREQ=DAILY;UNTIL=20110824T232454Z;BYHOUR=7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23;BYMINUTE=23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22”;
// To find next occurrence
// This is the specific date, for which you want to find next occurrence
DateTime specificDate = new DateTime(2009, 11, 18, 07, 10, 54);
// Create another recurrence pattern
RecurrencePattern recPattern2 = new RecurrencePattern(pattern);
// Set start date to the specific date
recPattern2.StartDate = specificDate;
// Set count to 100
recPattern2.RRules[0].Count = 100;
// Generate dates
DateCollection dtColl = recPattern2.GenerateOccurrences();
Console.WriteLine("Date: " + specificDate);
Console.WriteLine("Next occurrence: " + dtColl[1]);
Please note that if we set count to 2, then next occurrence might be incorrect, because BYMINUTE rule starts from 23. Example:
18.11.2009 7:10:54
18.11.2009 7:23:54
To fix this, we set the count to 100 to consider the whole values in the MINUTE rule.
Thanks Saqib,