Identifying multiple days all day event


  • Anonymous

    I created an all day event in Google Calender.It is a multiple days all day event (15-09-2001 to 17-09-2011)
    I downloaded .ics file for that  event from Google calender and imported into my java web application.
    But I'am getting my system timezone as the Event  Start Time and End Time  though it is as all day event.

    This is a Google ics file which I doenloaded from Google Calender.

    PRODID:-//Google Inc//Google Calendar 70.9054//EN
    SUMMARY:google_india_all day(15)

    I want to know how to identify that this is an all day event.

  • Pascal Robert
    Pascal Robert

    To identify if it's a all-day event, you need to check if DTSTART and DTEND have the time or not. In this case, both only have the date (YYYYMMDD), so it's an all-day event. Yeah, this is how the RFC iCalendar says it should work.


  • Anonymous

    please correct following two in above .ics file



  • Anonymous

    I write the following code to get the event start date but it gives the DTSTART with time(YYYYMMDDHHmmss).

    DateTime stDt = new DateTime(vevent.getStartDate().getDate());

    The time it sets is the timezone of my system (+5.30)

    stDt have value: 20110915T053000

    it should be 20110915 or may be 20110915000000

  • Pascal Robert
    Pascal Robert

    Use Date instead of DateTime and it will work.


  • Anonymous

    I have used Date as

    Date stDt = new Date(vevent.getStartDate().getDate().getTime());

    but it also gives the value of stDt :Thu Sep 15 05:30:00 GMT+05:30 2011 (with time 05:30:00) though there is no time in DTSTART as it is an all day event

  • LuckyLuigi

    For building allday event this works for me

    ve.getProperties().add(new DtStart(new Date(from.getTime())));
    ve.getProperties().add(new DtEnd(new Date(to.getTime())));

    Identifiying an allday event is a lot trickier. You will notice that many applications (especially mobile phones) will send you 'incorrect' vevents if they have allday appointments.
    Basically I treat all incoming vevents like this: If the event spans 23 hours or more on the same day (from 00:00 to 23:00+) OR it spans multiple days with identical hour and minute for DTSTART and DTEND, then I treat it as an allday event.

    Works good for me.

  • To check, whether a DateProperty is an all-day date I do this:

    !(dateProp.getDate() instanceof DateTime)

    And for date conversion code, I usually have an if/else:

    Date date = ...
    if (date instanceof DateTime) {
        // date + time
    } else {
        // date

    When converting it to other internal date representations, it is very important to handle pure dates separately, as you want to make sure you ignore the time zone for them… Storing them as 2011-09-19 0:00 +2:00 and then converting it over to e.g. the -9:00 timezone (which will automatically happen somewhere ;-)) will also affect the date, and you don't want that.


  • sebl29

    A user send me a facebook birthday event with DTSTART:20111010 and DURATION:P1D.

    When ical4j parses this, it becomes  DTSTART:20111010T000000 (seen in the debugger) and is an instance of DateTime (instead of Date). So how should I interprete this as an allDayEvent?

    I am using ical4j v1.0.2 via Maven.

  • LuckyLuigi

    VEVENTS with only a DTSTART (no DTEND) parameter are 'anniversaries' if it is DATE value and 'daily reminders' if it is a DATETIME. Both kinds take up 'zero' time.
    Your problem is interesting as the parsing changes the anniversary to a daily reminder. I'd explicitly code an exception for midnight datetimes to be handled as dates in this case.

  • sebl29

    Hi lgonggr,

    but wouldn't it be better, if ical4j recognizes this value as a Date-object, instead of an DateTime-object, even if  'VALUE=DATE' is missing? IMHO there should be a fallback to a date-value, instead of complementing 0h, 0min, 0sec ("T000000"), as this distorts the original value (and we even have to think about time-zones etc).
    And adding an exception for midnight, and perhaps also adding the constraint of the DURATION xor checking DTEND (checking both, date and datetime values) to fit 24h, is a rather bad workaround IMHO, instead of returning the expected date-object.
    Perhaps I do not see the advantage of your suggestion, or do you agree with my one?

    I didn't look at the reminders yet.

  • LuckyLuigi

    Disclaimer : I am not using the latest version of ical4j however and I am aware there have been changes in how these cases (amongst others) are handled in the code in later versions. In fact this is one of the reasons I have not managed to convince my superiors we should upgrade to the latest version of ical4j. But I digress..

    I partly agree with you. In theory I support that ical4j should work as you describe, but in actual practice I don't.

    In practice the majority of programs bluntly violate the RFCs (and the RFCs are inconsistent with themselves in some areas) and while ical4j flexible parsing is extremely good, it cannot handle everything and you will be forced to accomodate for this in your code so 'exception handling' is unavoidable. In order to handle RFC violations correctly I need to be able to rely on ical4j to parse as accurately as possible and not to do exception handling itself. If ical4j starts getting clever on me I will not be able to tell easily if ical4j is the culprit or the original icalendar message.

  • Ken


    Currently I determine my 'Allday' events using this method.  It seems to look for half the criteria you are looking for.  Can you help me with the part that is missing? - Thanks.

         * Determines if the event is an all day event based on whether or not 'DATE' is include in the value
         * @param event
         * @return boolean
        private static boolean isEventAllDay(VEvent event){
            return event.getStartDate().toString().indexOf("VALUE=DATE") != -1;