1

我有以下使用双周创建和 ics 字符串的方法:

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;
}

生成以下内容:

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

问题是当我通过电子邮件将其发送到我的 gmail 帐户时,仅显示第一个事件。起初我认为这是 Biweekly 的问题,但看起来 ics 输出是正确的。ics输出有问题吗?

4

2 回答 2

0

如果您通过电子邮件发送此 ics 流,您应该在 VCALENDAR 对象的开头有一个 METHOD:PUBLISH 属性并遵循 iTIP ( https://www.rfc-editor.org/rfc/rfc5546 ) 和 iMIP的规则(https://www.rfc-editor.org/rfc/rfc6047)。

完成后,某些客户端(例如 gmail)也很可能不接受同一日历邀请中的多个事件。

最后(相当美观的)评论:VTIMEZONE 组件通常放置在 iCalendar 流的顶部。

于 2015-12-01T08:35:27.523 回答
-1

嗨,tad:它对我有用。这是我的做法:

  1. 单击“我的日历”右侧的小向下箭头,然后选择“设置”。
  2. 单击“导入日历”(“创建日历”按钮旁边)。
  3. 在文件选择器中选择 .ics 文件。
  4. 请注意在“日历”下拉列表中选择的日历的名称。
  5. 点击“导入”。
  6. 出现一个对话框,上面写着“已导入 2 个事件”。
  7. 确保第 4 步中的日历可见,然后转到 12/1 和 12/2 查看事件。
于 2015-11-29T14:30:22.210 回答