Bug in 'add Date to DateList'

2010-05-11
2013-06-05
  • Tom Deschepper

    Tom Deschepper - 2010-05-11

    When I add a DateTime 'date' to a DateList, the timezone of date is set to null.

    Can easly be solved by taking a clone before adding but if it's a bug, I just wanted to let you know.
     

    public void addExDate(net.fortuna.ical4j.model.Date date) {
            if (event.getProperty(Property.EXDATE) == null) {
                ExDate exdate = new ExDate();
                exdate.getDates().add(date);
                if (date instanceof DateTime) {
                    if (((DateTime) date).isUtc()) {
                        exdate.setUtc(((DateTime) dateclone).isUtc());
                    } else {
                        exdate.setTimeZone(((DateTime) date).getTimeZone());
                    }
                }
                event.getProperties().add(exdate);
            } else {
                ((ExDate) event.getProperty(Property.EXDATE)).getDates().add(date);
            }
    

    }

     
  • Alexander Klimetschek

    You can initialize the date list, before adding dates. This is what I am doing:

        private static DateList createDateList(boolean isDate, TimeZone timeZone) {
            DateList dateList;
            if (isDate) {
                dateList = new DateList(net.fortuna.ical4j.model.parameter.Value.DATE);
            } else {
                dateList = new DateList(net.fortuna.ical4j.model.parameter.Value.DATE_TIME);
            }
            if (timeZone != null && TimeZones.isUtc(timeZone)) {
                dateList.setUtc(true);
            } else {
                dateList.setTimeZone(timeZone);
            }
            return dateList;
        }
    

    And then with ExDate:

    DateList exceptionList = createDateList(isDate, timeZone);
    // add dates to list
    exceptionList.add(....);
    ExDate date = new ExDate(exceptionList);
    

    -Alex

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks