0 votes

How do you define last week in month for the recurring rule when using ByWeekNumber? In Outlook, they use Last as the designation. So, if I have a recurring rule that is Last Wednesday in the month, how do I describe the rule?

by (550 points)

1 Answer

0 votes

BYWEEKNO (ByWeekNumber) rule part is only valid for YEARLY rules (Frequency.Yearly)

Last Wednesday in the month is:

RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=-1WE

The code for that is:

RecurringRule recurring = new RecurringRule();
recurring.Frequency = Frequency.Monthly;
recurring.ByDay.Add(Weekday.LastWednesday);

Creating an email with such rule:

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();
e.SetOrganizer(new Person("Frank From", "from@example.com"));
e.AddParticipant(new Participant("Tom To", "to@example.com"));
e.Description = "Event description";
e.Summary = "Event summary";
e.Start = new DateTime(2014, 11, 26, 9, 0, 0);
e.End = new DateTime(2014, 11, 26, 10, 0, 0);

RecurringRule recurring = e.AddRecurringRule();
recurring.Frequency = Frequency.Monthly;
recurring.ByDay.Add(Weekday.LastWednesday);

Alarm alarm = e.AddAlarm();
alarm.Description = "Reminder";
alarm.BeforeStart(TimeSpan.FromMinutes(5));

var builder = new MailBuilder();
builder.Subject = "with appointment";
builder.From.Add(new MailBox("from@example.com"));
builder.To.Add(new MailBox("to@example.com"));
builder.Text = "Some text. Appointment is attached";
builder.AddAppointment(appointment);
IMail email = builder.Create();
by (272k points)
edited by
How do you describe weeks two and three?
...