1

I am new to iCalendar and ical4j and the data model seems to be very hard to understand.

I have an Outlook-generated iCalendar, and my goal is to get the meeting start time in UTC (DTSTART).

The calendar parses correctly and seems to be reading DTSTART correctly.

String vCalString =

                "BEGIN:VCALENDAR\n" + "METHOD:REQUEST\n" + "PRODID:Microsoft Exchange Server 2010\n"
                + "VERSION:2.0\n" + "BEGIN:VTIMEZONE\n" + "TZID:Eastern Standard Time\n" + "BEGIN:STANDARD\n"
                + "DTSTART:16010101T020000\n" + "TZOFFSETFROM:-0400\n" + "TZOFFSETTO:-0500\n"
                + "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11\n" + "END:STANDARD\n" + "BEGIN:DAYLIGHT\n"
                + "DTSTART:16010101T020000\n" + "TZOFFSETFROM:-0500\n" + "TZOFFSETTO:-0400\n"
                + "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3\n" + "END:DAYLIGHT\n" + "END:VTIMEZONE\n"
                + "BEGIN:VEVENT\n" + "ORGANIZER;CN=John Smith:mailto:John.Smith@example.com\n"
                + "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=contact@anotherco.com:mailto:contact@anotherco.com\n"
                + "DESCRIPTION;LANGUAGE=en-US:Lets discuss financials\n"
                + "UID:040000008200E00074C5B7101A82E0080000000015BD10D55838D601000000000000000"
                + "01000000036936282CECE8A4E868397E00A27F5D2\n" + "SUMMARY;LANGUAGE=en-US:Strat planning\n"
                + "DTSTART;TZID=Eastern Standard Time:20200601T170000\n"
                + "DTEND;TZID=Eastern Standard Time:20200601T173000\n" + "CLASS:PUBLIC\n" + "PRIORITY:5\n"
                + "DTSTAMP:20200601T210843Z\n" + "TRANSP:OPAQUE\n" + "STATUS:CONFIRMED\n" + "SEQUENCE:0\n"
                + "LOCATION;LANGUAGE=en-US:https://www.zoom.us/j/12345678\n"
                + "X-MICROSOFT-CDO-APPT-SEQUENCE:0\n" + "X-MICROSOFT-CDO-OWNERAPPTID:2118519317\n"
                + "X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\n" + "X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\n"
                + "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE\n" + "X-MICROSOFT-CDO-IMPORTANCE:1\n"
                + "X-MICROSOFT-CDO-INSTTYPE:0\n" + "X-MICROSOFT-DONOTFORWARDMEETING:FALSE\n"
                + "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n"
                + "X-MICROSOFT-LOCATIONDISPLAYNAME:https://www.zoom.us/j/12345678\n"
                + "X-MICROSOFT-LOCATIONSOURCE:None\n" + "BEGIN:VALARM\n"
                + "DESCRIPTION:REMINDER\n" + "TRIGGER;RELATED=START:-PT15M\n" + "ACTION:DISPLAY\n" + "END:VALARM\n"
                + "END:VEVENT\n" + "END:VCALENDAR";

        System.setProperty("net.fortuna.ical4j.timezone.cache.impl", MapTimeZoneCache.class.getName());

        CalendarBuilder builder = new CalendarBuilder();
        Calendar cal = null;
        try
        {
            cal = builder.build(new ByteArrayInputStream(vCalString.getBytes()));
            cal.validate();

            VTimeZone vTimeZone = (VTimeZone) cal.getComponent(Component.VTIMEZONE);
            System.out.println("VTimeZone = " + vTimeZone.getTimeZoneId().getValue());

            VEvent ve = (VEvent) cal.getComponent(Component.VEVENT);
            System.out.println("VEvent: " + ve.getDescription().getValue());

            DtStart dts = ve.getProperty(Property.DTSTART);

            System.out.println("DtStart: " + dts.getDate());
            System.out.println("DtStart TZID: " + dts.getParameter(Property.TZID));

This is the output.

VTimeZone = Eastern Standard Time
VEvent: Lets discuss financials
DtStart: 2020-06-01T17:00-04:00[ical4j~0d2f1059-f091-485a-b24c-119ed011a1ff]
DtStart TZID: Optional[TZID=Eastern Standard Time]

So my 'dts' object seems to contain both time stamp and time zone (and that weird [ical4j~...] thing). But at this point, what next? I am lost amidst Temporals and not sure how to convert this to a UTC

Thank you!

PVS
  • 69
  • 9
  • Have you researched and tried setTimeZone? – anmari Jun 03 '20 at 03:59
  • I need something along the lines of a DtStart.getUTC(). As mentioned in my question, I already have a DtStart object which contains timezone information. ```DtStart: 2020-06-01T17:00-04:00[ical4j~0d2f1059-f091-485a-b24c-119ed011a1ff]``` – PVS Jun 03 '20 at 14:39
  • RE "not sure how to convert this to a UTC" - in the php world one would use set timezone. IE set the timezone of the datetime object to UTC, then its formatted output would be in UTC. – anmari Jun 04 '20 at 00:16

0 Answers0