/** * Instantiate a new datelist with the same type, timezone and utc settings * as the origList. * @param origList * @return a new empty list. */ private static DateList getDateListInstance(final DateList origList) { final DateList list = new DateList(origList.getType()); if (origList.isUtc()) { list.setUtc(true); } else { list.setTimeZone(origList.getTimeZone()); } return list; }
@Override public DateList transform(DateList dates) { // return if no SETPOS rules specified.. if (setPosList.isEmpty()) { return dates; } // sort the list before processing.. Collections.sort(dates); final DateList setPosDates = Dates.getDateListInstance(dates); final int size = dates.size(); for (final Integer setPos : setPosList) { final int pos = setPos; if (pos > 0 && pos <= size) { setPosDates.add(dates.get(pos - 1)); } else if (pos < 0 && pos >= -size) { setPosDates.add(dates.get(size + pos)); } } return setPosDates; } }
/** * Returns a single-element sublist containing the element of <code>list</code> at <code>offset</code>. Valid * offsets are from 1 to the size of the list. If an invalid offset is supplied, all elements from <code>list</code> * are added to <code>sublist</code>. * @param offset */ private List getOffsetDates(final DateList dates, final int offset) { if (offset == 0) { return dates; } final List offsetDates = getDateListInstance(dates); final int size = dates.size(); if (offset < 0 && offset >= -size) { offsetDates.add(dates.get(size + offset)); } else if (offset > 0 && offset <= size) { offsetDates.add(dates.get(offset - 1)); } return offsetDates; }
final DateList dates = new DateList(value); if (seed instanceof DateTime) { if (((DateTime) seed).isUtc()) { dates.setUtc(true); dates.setTimeZone(((DateTime) seed).getTimeZone()); int noCandidateIncrementCount = 0; Date candidate = null; while ((maxCount < 0) || (dates.size() < maxCount)) { final Date candidateSeed = Dates.getInstance(cal.getTime(), value); && (dates.size() + invalidCandidateCount) >= getCount()) { if (dates.isUtc()) { ((DateTime) candidateSeed).setUtc(true); ((DateTime) candidateSeed).setTimeZone(dates.getTimeZone()); if (!candidates.isEmpty()) { noCandidateIncrementCount = 0; for (final Iterator i = candidates.iterator(); i.hasNext();) { candidate = (Date) i.next(); invalidCandidateCount++; } else if (getCount() >= 1 && (dates.size() + invalidCandidateCount) >= getCount()) { break;
@Override public DateList transform(DateList dates) { if (hourList.isEmpty()) { return dates; } final DateList hourlyDates = Dates.getDateListInstance(dates); for (final Date date : dates) { if (EnumSet.of(DAILY, WEEKLY, MONTHLY, YEARLY).contains(getFrequency())) { hourlyDates.addAll(new ExpansionFilter(hourlyDates.getType()).apply(date)); } else { Optional<Date> limit = new LimitFilter().apply(date); if (limit.isPresent()) { hourlyDates.add(limit.get()); } } } return hourlyDates; }
public DateList getExceptionDates() { DateList dateList = null; PropertyList<ExDate> exDatesProperties = getEvent().getProperties().getProperties(Property.EXDATE); for (ExDate exdate : exDatesProperties) { if(dateList==null) { if(Value.DATE.equals(exdate.getParameter(Parameter.VALUE))) { dateList = new DateList(Value.DATE); } else { dateList = new DateList(Value.DATE_TIME, exdate.getDates().getTimeZone()); } } dateList.addAll(exdate.getDates()); } return dateList; }
final DateList days = new DateList(type); if (date instanceof DateTime) { if (((DateTime) date).isUtc()) { days.setUtc(true); } else { days.setTimeZone(((DateTime) date).getTimeZone()); days.add(Dates.getInstance(cal.getTime(), type)); days.add(Dates.getInstance(cal.getTime(), type)); days.add(Dates.getInstance(cal.getTime(), type)); cal.add(Calendar.DAY_OF_MONTH, Dates.DAYS_PER_WEEK); days.add(Dates.getInstance(cal.getTime(), type)); cal.add(Calendar.DAY_OF_YEAR, Dates.DAYS_PER_WEEK);
/** * Add a date to the list. The date will be updated to reflect the * timezone of this list. * @param date the date to add * @return true * @see List#add(java.lang.Object) */ public final boolean add(final Date date) { if (date instanceof DateTime) { if (isUtc()) { ((DateTime) date).setUtc(true); } else { ((DateTime) date).setTimeZone(getTimeZone()); } } else if (!Value.DATE.equals(getType())) { final DateTime dateTime = new DateTime(date); dateTime.setTimeZone(getTimeZone()); return add((Object) dateTime); } return add((Object) date); }
/** * @param name the property name */ public DateListProperty(final String name, PropertyFactory factory) { this(name, new DateList(Value.DATE_TIME), factory); }
/** * Resets the timezone associated with the property. If utc is true, any TZID parameters are removed and the Java * timezone is updated to UTC time. If utc is false, TZID parameters are removed and the Java timezone is set to the * default timezone (i.e. represents a "floating" local time) * * @param utc the UTC value */ public final void setUtc(final boolean utc) { if (dates == null || !Value.DATE_TIME.equals(dates.getType())) { throw new UnsupportedOperationException( "TimeZone is not applicable to current value"); } dates.setUtc(utc); getParameters().remove(getParameter(Parameter.TZID)); }
@Override public boolean toVEvent(final TeamEventDO event, final VEvent vEvent) { if (event.hasRecurrence() == false || event.getRecurrenceExDate() == null) { return false; } final List<Date> exDates = ICal4JUtils.parseCSVDatesAsICal4jDates(event.getRecurrenceExDate(), (false == event.isAllDay()), ICal4JUtils.getUTCTimeZone()); if (CollectionUtils.isEmpty(exDates)) { return false; } for (final Date date : exDates) { final DateList dateList; if (event.isAllDay() == true) { dateList = new DateList(Value.DATE); } else { dateList = new DateList(); dateList.setUtc(true); } dateList.add(date); ExDate exDate; exDate = new ExDate(dateList); vEvent.getProperties().add(exDate); } return true; }
/** * Sets the timezone associated with this property. * * @param timezone a timezone to associate with this property */ public void setTimeZone(final TimeZone timezone) { if (dates == null) { throw new UnsupportedOperationException( "TimeZone is not applicable to current value"); } this.timeZone = timezone; if (timezone != null) { if (!Value.DATE_TIME.equals(getDates().getType())) { throw new UnsupportedOperationException( "TimeZone is not applicable to current value"); } dates.setTimeZone(timezone); getParameters().remove(getParameter(Parameter.TZID)); final TzId tzId = new TzId(timezone.getID()); getParameters().replace(tzId); } else { // use setUtc() to reset timezone.. setUtc(false); } }
/** * Add a date to the list. The date will be updated to reflect the * timezone of this list. * @param date the date to add * @return true * @see List#add(java.lang.Object) */ public final boolean add(final Date date) { if (date instanceof DateTime) { if (isUtc()) { ((DateTime) date).setUtc(true); } else { ((DateTime) date).setTimeZone(getTimeZone()); } } else if (!Value.DATE.equals(getType())) { final DateTime dateTime = new DateTime(date); dateTime.setTimeZone(getTimeZone()); return dates.add(dateTime); } return dates.add(date); }
/** * Applies BYMINUTE rules specified in this Recur instance to the specified date list. If no BYMINUTE rules are * specified the date list is returned unmodified. * * @param dates * @return */ private DateList getMinuteVariants(final DateList dates) { if (getMinuteList().isEmpty()) { return dates; } final DateList minutelyDates = getDateListInstance(dates); for (final Date date : dates) { final Calendar cal = getCalendarInstance(date, true); for (final Integer minute : getMinuteList()) { cal.set(Calendar.MINUTE, minute); minutelyDates.add(Dates.getInstance(cal.getTime(), minutelyDates.getType())); } } return minutelyDates; }
/** * Constructs an <code>ICalDate</code> from an iCalendar date * list. Date lists cannot be anytime. * @param dates The date list. * @throws UnknownTimeZoneException - if something is wrong this exception is thrown. */ public ICalDate(DateList dates) throws UnknownTimeZoneException { value = dates.getType(); tz = dates.getTimeZone(); if (tz != null) { String origId = tz.getID(); tz = tzTranslator.translateToOlsonTz(tz); if (tz == null) { throw new UnknownTimeZoneException(origId); } String id = tz.getVTimeZone().getProperties(). getProperty(Property.TZID).getValue(); tzid = new TzId(id); } text = dates.toString(); this.dates = dates; }
/** * */ public void testGetDatesNotEmpty() { assertFalse(recur.getDates(periodStart, periodEnd, value).isEmpty()); }
public boolean isRecurring() { if(getRecurrenceRules().size()>0) { return true; } DateList rdates = getRecurrenceDates(); return rdates!=null && rdates.size()>0; }
/** * @param name the property name * @param parameters property parameters * @param dates a list of initial dates for the property */ public DateListProperty(final String name, final ParameterList parameters, final DateList dates, PropertyFactory factory) { super(name, parameters, factory); this.dates = dates; if (dates != null && !Value.DATE_TIME.equals(dates.getType())) { getParameters().replace(dates.getType()); } }
protected void setDateListPropertyValue(DateListProperty prop) { if (prop == null) { return; } Value value = (Value) prop.getParameters().getParameter(Parameter.VALUE); if (value != null) { prop.getParameters().remove(value); } value = prop.getDates().getType(); // set VALUE=DATE but not VALUE=DATE-TIME as its redundant if(value.equals(Value.DATE)) { prop.getParameters().add(value); } // update timezone for now because ical4j DateList doesn't Parameter param = (Parameter) prop.getParameters().getParameter( Parameter.TZID); if (param != null) { prop.getParameters().remove(param); } if(prop.getDates().getTimeZone()!=null) { prop.getParameters().add(new TzId(prop.getDates().getTimeZone().getID())); } }