Free Support Forum - aspose.com

Bug in iCalendar implementation?

I'm trying your iCalendar trial.

Am I doing something wrong to get ByHour to work?

the mRule (RecurrenceRule) does not allow one to set the ByHour property (it says it's read only).

Also, it seems that I cannot instantiate the ByNumberCollection either. It appears to have no constructor?

How can one set the byhour properties if these are not available in the RecurrenceRule?

I think I can hack the iCalendar output of the RecurrenceRule and add the ByHour to the resulting iCalendar string. But it would be cleaner if the class did it.

Suggestions?


This message was posted using Aspose.Live 2 Forum

Hi,

Sorry for replying on this late.

ByHour, ByDay etc properties are actually collections and you can use them by calling Add() method on the collections. The sample code for generating dates for all weekdays and 9 to 5 would be as below:

RecurrencePattern pattern = new RecurrencePattern();
pattern.StartDate = DateTime.Parse(“3/1/2010 9:00 AM”);
// add repeating rule
RecurrenceRule rule = pattern.RRules.Add();
// repeat daily
rule.Frequency = Frequency.Daily;
// until
rule.Until = DateTime.Parse(“3/30/2010 5:00 PM”);
// specify days
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);
// hours
rule.ByHour.Add(new int[] { 9, 10, 11, 12, 13, 14, 15, 16 });

Console.WriteLine("Recurrence Pattern: " + pattern.ToiCalendar());

// Generate the dates
DateCollection dates = pattern.GenerateOccurrences();
foreach (DateTime date in dates)
{
Console.WriteLine(date.ToString());
}