Menu

Bug in ICalDate(Date, DateTimeComponents, boolean)

Anonymous
2015-09-22
2015-10-16
  • Anonymous

    Anonymous - 2015-09-22

    This constructor uses the Calendar class to remove the time components from the specified date. The Calendar object returned from Calendar.getInstance defaults to using the default timezone for the device (machine). This causes the resulting date to be offset by the default timezone’s offset from UTC. As an example:

    I want to create an all day event with a start date of 9/24/2015 and end date of 9/25/2015. I pass in a date object for 9/24/2015 00:00:00, and 9/25/2015 00:00:00 (obviously UTC, since all Dates are UTC). My timezone is CDT (UTC-5:00). What happens is, the Calendar object has a time of 9/23/2015 19:00:00, because it’s in CDT time, and I end up with a date of 9/23/2015 with the time components removed.

    This should be a simple matter of adding the line: c.setTimeZone(TimeZone.getTimeZone("UTC”));

     
  • Michael Angstadt

    Thanks of the report. Sorry for the late reply.

    When creating dates that don't have time components, always use the default timezone when creating the Date object.

    There was a bug related to inproper casting. After the bug fix, I was able to successfully create a VEVENT that had start/end dates without time components. Please let me know if this still doesn't solve your issue.

    :::java
    ICalendar ical = new ICalendar();
    VEvent event = new VEvent();
    
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, 2015);
    c.set(Calendar.MONTH, Calendar.OCTOBER);
    c.set(Calendar.DATE, 15);
    Date from = c.getTime();
    event.setDateStart(from, false);
    
    c.set(Calendar.DATE, 16);
    Date to = c.getTime();
    event.setDateEnd(to, false);
    
    ical.addEvent(event);
    
    System.out.println(ical.write());
    

    Produces:

    :::text
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//Michael Angstadt//biweekly 0.4.3-SNAPSHOT//EN
    BEGIN:VEVENT
    UID:8e87cf55-ef94-477d-a9cb-78c9ea19436a
    DTSTAMP:20151016T002009Z
    DTSTART;VALUE=DATE:20151015
    DTEND;VALUE=DATE:20151016
    END:VEVENT
    END:VCALENDAR
    

    Fixed in: b6b229e23d10ddd4c6cb123c202d813de34cb834

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.