1

I have the following method that uses biweekly to create and ics string:

public String createICalendarString(List<ICalendarEventVo> iCalendarEventVos, String locale, String timeZoneCanonicalId) throws IOException
{
    String icsLocale = convertLocaleToIcsFormat(locale);
    ICalendar ical = new ICalendar();
    for (ICalendarEventVo iCalendarEventVo : iCalendarEventVos)
    {
        VEvent event = new VEvent();
        Summary summary = new Summary(iCalendarEventVo.getSummaryText());
        summary.setLanguage(icsLocale);
        event.setSummary(summary);

        if (null != iCalendarEventVo.getDescriptionText())
        {
            Description description = new Description(iCalendarEventVo.getDescriptionText());
            description.setLanguage(icsLocale);
            event.setDescription(description);
        }

        if (null != iCalendarEventVo.getLocationText())
        {
            Location location = new Location(iCalendarEventVo.getLocationText());
            location.setLanguage(icsLocale);
            event.setLocation(location);
        }

        if (null != iCalendarEventVo.getOrganizerName() && null != iCalendarEventVo.getOrganizerEmail())
        {
            Organizer organizer = new Organizer(iCalendarEventVo.getOrganizerName(), iCalendarEventVo.getOrganizerEmail());
            event.setOrganizer(organizer);
        }

        event.setDateStart(iCalendarEventVo.getStartDate());
        event.setDateEnd(iCalendarEventVo.getEndDate());
        event.setUid(iCalendarEventVo.getUid());

        ical.addEvent(event);
    }

    String icsString = null;

    try (StringWriter writer = new StringWriter();
            ICalWriter icalWriter = new ICalWriter(writer, ICalVersion.V2_0);)
    {
        //optional: Use Outlook-friendly VTIMEZONE components:
        icalWriter.getTimezoneInfo().setGenerator(new TzUrlDotOrgGenerator(true));

        //output date/time values in the timeZone that was passed in
        TimeZone timeZone = TimeZone.getTimeZone(timeZoneCanonicalId);
        icalWriter.getTimezoneInfo().setDefaultTimeZone(timeZone);

        icalWriter.write(ical);
        icsString = writer.toString();
    }
    return icsString;
}

Which generates the following:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.4.4//EN
BEGIN:VEVENT
DTSTAMP:20151128T030141Z
SUMMARY;LANGUAGE=en-us:Test ILT Class: Session #1
DESCRIPTION;LANGUAGE=en-us:Test ILT Class goes through what is needed to ma
 ke a sale. The session will be about looking nice for your customer.
LOCATION;LANGUAGE=en-us:Statue of Liberty - Meet at the top of the crown.
ORGANIZER;CN=TorchLMS:mailto:no-reply@torchlms.com
DTSTART;TZID=America/New_York:20151201T190000
DTEND;TZID=America/New_York:20151201T220000
UID:TLMS_SESSION_1000110010000000000_1000110210000000051
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20151128T030141Z
SUMMARY;LANGUAGE=en-us:Test ILT Class: Session #2
DESCRIPTION;LANGUAGE=en-us:Test ILT Class goes through what is needed to ma
 ke a sale. This session will talk about how to blow sunshine in the direct
 ion of the customer.
LOCATION;LANGUAGE=en-us:World Trade Center - Top floor in the penthouse
ORGANIZER;CN=TorchLMS:mailto:no-reply@torchlms.com
DTSTART;TZID=America/New_York:20151202T170000
DTEND;TZID=America/New_York:20151202T190000
UID:TLMS_SESSION_1000110010000000000_1000110210000000101
END:VEVENT
BEGIN:VTIMEZONE
TZID:America/New_York
TZURL:http://tzurl.org/zoneinfo-outlook/America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
END:STANDARD
END:VTIMEZONE
END:VCALENDAR

The problem is when I email this to my gmail account only the first event shows up. At first I thought this was an issue with Biweekly, but it looks like the ics out put is correct. Is there something wrong with the ics output?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
testing123
  • 11,367
  • 10
  • 47
  • 61

2 Answers2

0

If you are sending this ics stream via email, you should have a METHOD:PUBLISH property at the beginning of your VCALENDAR object and follow the rules of iTIP (https://www.rfc-editor.org/rfc/rfc5546) and iMIP (https://www.rfc-editor.org/rfc/rfc6047).

Once you are done, it is also quite possible that some clients (e.g. gmail) do not accept multiple events in the same calendar invitation.

A last (rather aesthetic) comment: the VTIMEZONE component is usually placed at the top of the iCalendar stream.

Community
  • 1
  • 1
Arnaud Quillaud
  • 4,420
  • 1
  • 12
  • 8
  • I am using the biweekly library so the order is not really within my control. I will try playing around with the ics file manually though to see if any of your suggestions work and then let Mike (the creator of biweekly) know if any of them fix the issue. – testing123 Dec 01 '15 at 16:38
-1

Hi tad: It worked for me. Here is how I did it:

  1. Click on the little down arrow to the right of "My calendars" and select "Settings".
  2. Click on "Import Calendar" (next to the "Create calendar" button).
  3. Select the .ics file in the file chooser.
  4. Note the name of the calendar that's selected in the "Calendar" dropdown list.
  5. Click "Import".
  6. A dialog box appears that says something like "2 events imported".
  7. Make sure the calendar from step 4 is visible, and go to 12/1 and 12/2 to see the events.
Michael
  • 34,873
  • 17
  • 75
  • 109
  • 1
    You are right that the import works. Gmail shows a visual representation of the ics file. When I put two events in the ics file it only shows one of the events and it looks like it is only a calendar event for the one event instead of the two events. Like mentioned in the other answer, it may be gmail doesn't support it. I am going to play around with this some more tomorrow and see if I can get both events to show up. Thanks for your answer. – testing123 Dec 01 '15 at 16:36