Yearly Recurrence pattern is wrong

Hi,
I have to create yearly recurrence pattern. But after creating recurrence and open pst in Microsoft Outlook on windows then it is showing end date increasing by one. Suppose my start date is 13/09/2017 and end date is 13/09/2025 then after creating it shows 13/09/2026. I need 13/09/2025. Please take input from your end whatever you want.(take occurrence count 10). Please kindly update me.

@kharade.a,

Please try the sample code snippet given below at you end and share your feedback.

CODE:

DateTime startDate = new DateTime(2017, 09, 13); // 13/09/2017

DateTime endByDate = new DateTime(2025, 09, 13); // 13/09/2025

Aspose.Email.Mapi.MapiCalendar cal = new Aspose.Email.Mapi.MapiCalendar("location", "Summary", "Description", startDate, endByDate);

// Set the Yearly recurrence
Aspose.Email.Mapi.MapiCalendarMonthlyRecurrencePattern rec = new Aspose.Email.Mapi.MapiCalendarMonthlyRecurrencePattern();
{
    rec.Day = 15;
    rec.Period = 12;
    rec.PatternType  = Aspose.Email.Mapi.MapiCalendarRecurrencePatternType.Month;
    rec.EndType = Aspose.Email.Mapi.MapiCalendarRecurrenceEndType.EndAfterNOccurrences;
    rec.OccurrenceCount = 10;
};

//Generate recurrence event from the defined recurrence
Aspose.Email.Mapi.MapiCalendarEventRecurrence reccurrence = new 
Aspose.Email.Mapi.MapiCalendarEventRecurrence();
reccurrence.RecurrencePattern = rec;

//now create mapi calendar and set its recurrence
cal.Recurrence = reccurrence;

Aspose.Email.Storage.Pst.PersonalStorage pst = Aspose.Email.Storage.Pst.PersonalStorage.Create("YearlyPst.pst", 
Aspose.Email.Storage.Pst.FileFormatVersion.Unicode);

Aspose.Email.Storage.Pst.FolderInfo fi = pst.CreatePredefinedFolder("CalPst", 
Aspose.Email.Storage.Pst.StandardIpmFolder.Appointments);

 fi.AddMapiMessageItem(cal);
 pst.Dispose();

Hi,
Day is wrong in above example. You have to take 13 as day . Please try this for Aspose.Email For java API in java.

@kharade.a,

The sample code is given below and the generated PST file also attached for your reference.

CODE:

   java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT"));

    calendar.set(2016, java.util.Calendar.JULY, 1, 0, 0, 0);
    java.util.Date startDate = calendar.getTime();

    calendar.set(2016, java.util.Calendar.DECEMBER, 31, 0, 0, 0);
    java.util.Date endByDate = calendar.getTime();

    com.aspose.email.MapiCalendar cal = new com.aspose.email.MapiCalendar("location","Summary", "Description", startDate, endByDate);

    // Set the Yearly recurrence
    com.aspose.email.MapiCalendarMonthlyRecurrencePattern rec = new com.aspose.email.MapiCalendarMonthlyRecurrencePattern();
    {
    rec.setDay(15);
    rec.setPeriod(12);
    rec.setPatternType(com.aspose.email.MapiCalendarRecurrencePatternType.Month);
    rec.setEndType(com.aspose.email.MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
    rec.setOccurrenceCount(3);
    };

    //Generate recurrence event from the defined recurrence
    com.aspose.email.MapiCalendarEventRecurrence reccurrence = new com.aspose.email.MapiCalendarEventRecurrence();
    reccurrence.setRecurrencePattern(rec);

    //now create mapi calendar and set its recurrence
    cal.setRecurrence(reccurrence);

    com.aspose.email.PersonalStorage pst = com.aspose.email.PersonalStorage.create("E:\\Ctrash\\Input\\YearlyPst.pst", com.aspose.email.FileFormatVersion.Unicode);

    com.aspose.email.FolderInfo fi = pst.createPredefinedFolder("CalPst", com.aspose.email.StandardIpmFolder.Appointments);

    fi.addMapiMessageItem(cal);

    pst.dispose();

YearlyPst.zip (6.1 KB)

@kharade.a,

In addition to the information shared by Ikram please note that if we use MapiCalendarRecurrenceEndType.EndAfterDate, then we can create recurrence up to a particular date like 2025-09-13. On the other hand if we use OccurrenceCount = 10, then end date will be in year 2026 because starting from year 2017 with occurrence count 10, will finish in year 2026. You may please give a try to the following sample code and share the feedback.

static void Email_163136_EndAfterDate()
{
    java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT"));

    calendar.set(2016, Calendar.SEPTEMBER, 13, 9, 0, 0);
    java.util.Date startDate = calendar.getTime();

    calendar.set(2016, java.util.Calendar.SEPTEMBER, 13, 9, 30, 0);
    java.util.Date endByDate = calendar.getTime();

    com.aspose.email.MapiCalendar cal = new com.aspose.email.MapiCalendar("location","Summary", "Description", startDate, endByDate);

    // Set the Yearly recurrence
    com.aspose.email.MapiCalendarMonthlyRecurrencePattern rec = new com.aspose.email.MapiCalendarMonthlyRecurrencePattern();
    {
        rec.setDay(13);
        rec.setPeriod(12);
        rec.setPatternType(com.aspose.email.MapiCalendarRecurrencePatternType.Month);
        rec.setEndType(MapiCalendarRecurrenceEndType.EndAfterDate);
        calendar.set(2025, java.util.Calendar.SEPTEMBER, 13, 9, 30, 0);
        rec.setEndDate(calendar.getTime());
    };

    //Generate recurrence event from the defined recurrence
    com.aspose.email.MapiCalendarEventRecurrence reccurrence = new com.aspose.email.MapiCalendarEventRecurrence();
    reccurrence.setRecurrencePattern(rec);

    //now create mapi calendar and set its recurrence
    cal.setRecurrence(reccurrence);
    cal.save("EndAfterDate.msg",AppointmentSaveFormat.Msg);

    com.aspose.email.PersonalStorage pst = com.aspose.email.PersonalStorage.create("EndAfterDate.pst", com.aspose.email.FileFormatVersion.Unicode);

    com.aspose.email.FolderInfo fi = pst.createPredefinedFolder("CalPst", com.aspose.email.StandardIpmFolder.Appointments);

    fi.addMapiMessageItem(cal);

    pst.dispose();
}

static void Email_163136_EndAfterNOccurrences()
{
    java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT"));

    calendar.set(2016, Calendar.SEPTEMBER, 13, 9, 0, 0);
    java.util.Date startDate = calendar.getTime();

    calendar.set(2016, java.util.Calendar.SEPTEMBER, 13, 9, 30, 0);
    java.util.Date endByDate = calendar.getTime();

    com.aspose.email.MapiCalendar cal = new com.aspose.email.MapiCalendar("location","Summary", "Description", startDate, endByDate);

    // Set the Yearly recurrence
    com.aspose.email.MapiCalendarMonthlyRecurrencePattern rec = new com.aspose.email.MapiCalendarMonthlyRecurrencePattern();
    {
        rec.setDay(13);
        rec.setPeriod(12);
        rec.setPatternType(com.aspose.email.MapiCalendarRecurrencePatternType.Month);
        rec.setEndType(com.aspose.email.MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
        rec.setOccurrenceCount(10);
    };

    //Generate recurrence event from the defined recurrence
    com.aspose.email.MapiCalendarEventRecurrence reccurrence = new com.aspose.email.MapiCalendarEventRecurrence();
    reccurrence.setRecurrencePattern(rec);

    //now create mapi calendar and set its recurrence
    cal.setRecurrence(reccurrence);
    cal.save("EndAfterNOccurrences.msg",AppointmentSaveFormat.Msg);

    com.aspose.email.PersonalStorage pst = com.aspose.email.PersonalStorage.create("EndAfterNOccurrences.pst", com.aspose.email.FileFormatVersion.Unicode);

    com.aspose.email.FolderInfo fi = pst.createPredefinedFolder("CalPst", com.aspose.email.StandardIpmFolder.Appointments);

    fi.addMapiMessageItem(cal);

    pst.dispose();
}