net.fortuna.ical4j.model.DateTime Java Examples

The following examples show how to use net.fortuna.ical4j.model.DateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void setDisplayAlarmTriggerDate(DateTime triggerDate) {
    VAlarm alarm = getDisplayAlarm();
    if(alarm==null) {
        return;
    }

    Trigger oldTrigger = (Trigger) alarm.getProperties().getProperty(
            Property.TRIGGER);
    if (oldTrigger != null) {
        alarm.getProperties().remove(oldTrigger);
    }
    
    Trigger newTrigger = new Trigger();
    newTrigger.getParameters().add(Value.DATE_TIME);
    newTrigger.setDateTime(triggerDate);
    
    alarm.getProperties().add(newTrigger);
}
 
Example #2
Source File: HibernateCalendarDaoTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMatchEventOneWithTimeRangeFilter() throws ParseException {
    // Time range test
    eventFilter.getPropFilters().clear();
    DateTime start = new DateTime("20050817T115000Z");
    DateTime end = new DateTime("20050818T115000Z");

    Period period = new Period(start, end);
    TimeRangeFilter timeRangeFilter = new TimeRangeFilter(period);
    eventFilter.setTimeRangeFilter(timeRangeFilter);

    // should match ics.1
    Set<ICalendarItem> queryEvents = calendarDao.findCalendarItems(calendar, filter);
    assertEquals(1, queryEvents.size());
    ContentItem nextItem = (ContentItem) queryEvents.iterator().next();
    assertEquals("test1.ics", nextItem.getName());
}
 
Example #3
Source File: HibernateTriageStatusQueryProcessorTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Tests get now collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetNowCollection() throws Exception {
    CollectionItem calendar = (CollectionItem) contentDao.findItemByUid(CALENDAR_UID);
    TriageStatusQueryContext context =
        new TriageStatusQueryContext(TriageStatus.LABEL_NOW, new DateTime("20070601T083000Z"), null);
    Set<NoteItem> now = queryProcessor.processTriageStatusQuery(calendar, context);
    Assert.assertEquals(5, now.size());
    
    // should be included because triage status is NOW
    verifyItemInSet(now,NOTE_UID + "mod");
    // should be included because its the parent of a modification included
    verifyItemInSet(now,NOTE_UID + "done");
    // should be included because triage status is null
    verifyItemInSet(now, "calendar2_2");
    // should be included because occurence overlaps instant in time
    verifyItemInSet(now,"calendar2_3:20070601T081500Z");
    // should be included because occurrence is included
    verifyItemInSet(now, "calendar2_3");
}
 
Example #4
Source File: StandardTriageStatusQueryProcessorTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Tests get all collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetAllCollection() throws Exception {
    CollectionItem calendar = (CollectionItem) contentDao.findItemByUid(CALENDAR_UID);
    TriageStatusQueryContext context =
        new TriageStatusQueryContext(null, new DateTime("20070601T000000Z"), null);
    Set<NoteItem> all = queryProcessor.processTriageStatusQuery(calendar, context);
    Assert.assertEquals(12, all.size());
    
    verifyItemInSet(all,NOTE_UID + "later");
    verifyItemInSet(all,NOTE_UID + "done");
    verifyItemInSet(all,NOTE_UID + "mod");
    verifyItemInSet(all,"calendar2_1:20070529T101500Z");
    verifyItemInSet(all,"calendar2_1:20070605T101500Z");
    verifyItemInSet(all,"calendar2_3:20070531T081500Z");
    verifyItemInSet(all,"calendar2_3:20070601T081500Z");
    verifyItemInSet(all,"calendar2_4:20080508T081500Z");
    verifyItemInSet(all,"calendar2_1");
    verifyItemInSet(all,"calendar2_2");
    verifyItemInSet(all,"calendar2_3");
    verifyItemInSet(all,"calendar2_4");
}
 
Example #5
Source File: IcalUtils.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a List of Appointments into a VCALENDAR component.
 *
 * @param appointments List of Appointments for the Calendar
 * @param ownerId      Owner of the Appointments
 * @return VCALENDAR representation of the Appointments
 */
public Calendar parseAppointmentstoCalendar(List<Appointment> appointments, Long ownerId) {
	String tzid = parseTimeZone(null, userDao.get(ownerId)).getID();

	TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

	net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid);
	if (timeZone == null) {
		throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid);
	}

	Calendar icsCalendar = new Calendar();
	icsCalendar.getProperties().add(new ProdId(PROD_ID));
	icsCalendar.getProperties().add(Version.VERSION_2_0);
	icsCalendar.getProperties().add(CalScale.GREGORIAN);
	icsCalendar.getComponents().add(timeZone.getVTimeZone());

	for (Appointment appointment : appointments) {
		DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd());

		VEvent meeting = new VEvent(start, end, appointment.getTitle());
		meeting = addVEventpropsfromAppointment(appointment, meeting);
		icsCalendar.getComponents().add(meeting);
	}
	return icsCalendar;
}
 
Example #6
Source File: ExpandRecurringEventsTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Verify expand calendar.
 * @param calendar The calendar.
 */
private void verifyExpandedCalendar(Calendar calendar) {
    // timezone should be stripped
    Assert.assertNull(calendar.getComponents().getComponent("VTIMEZONE"));
    
    ComponentList<VEvent> comps = calendar.getComponents().getComponents("VEVENT");
    
    for(VEvent event : comps) {
        DateTime dt = (DateTime) event.getStartDate().getDate();
        
        // verify start dates are UTC
        Assert.assertNull(event.getStartDate().getParameters().getParameter(Parameter.TZID));
        Assert.assertTrue(dt.isUtc());
        
        // verify no recurrence rules
        Assert.assertNull(event.getProperties().getProperty(Property.RRULE));
    }
}
 
Example #7
Source File: Calendar_EventRepeatMaster.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取重复时间表达式中结束的日期
 * @return
 */
public Date getRecurrenceEndDate() {
	final TimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry()
			.getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID());
	if (recurrenceRule != null) {
		try {
			final Recur recur = new Recur(recurrenceRule);
			final Date dUntil = recur.getUntil();
			final DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
			if (dtUntil != null) {
				dtUntil.setTimeZone(tz);
				return dtUntil;
			}
		} catch (final ParseException e) {
			System.out.println("cannot restore recurrence rule");
			e.printStackTrace();
		}
	}
	return null;
}
 
Example #8
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new DateTime instance for floating times (no timezone).
 * If the specified date is not floating, then the instance is returned. 
 * 
 * This allows a floating time to be converted to an instant in time
 * depending on the specified timezone.
 * 
 * @param date floating date
 * @param tz timezone
 * @return new DateTime instance representing floating time pinned to
 *         the specified timezone
 */
public static DateTime pinFloatingTime(Date date, TimeZone tz) {
    
    try {   
        if(date instanceof DateTime) {
            DateTime dt = (DateTime) date;
            if(dt.isUtc() || dt.getTimeZone()!=null) {
                return dt;
            }
            else {
                return new DateTime(date.toString(), tz);
            }
        }
        else {
            return new DateTime(date.toString() + "T000000", tz);
        }
    } catch (ParseException e) {
        throw new CosmoParseException("error parsing date", e);
    }
}
 
Example #9
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Return a Date instance that represents the day that a point in
 * time translates into local time given a timezone.
 * @param utcDateTime point in time
 * @param tz timezone The timezone.
 * @return The date.
 */
public static Date normalizeUTCDateTimeToDate(DateTime utcDateTime, TimeZone tz) {
    if(!utcDateTime.isUtc()) {
        throw new IllegalArgumentException("datetime must be utc");
    }
    
    // if no timezone, use default
    if (tz == null) {
        return new Date(utcDateTime);
    }
    
    DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime);
    copy.setTimeZone(tz);
    
    try {
        return new Date(copy.toString().substring(0, 8));
    } catch (ParseException e) {
        throw new CosmoParseException("error creating Date instance", e);
    }
}
 
Example #10
Source File: ICalendarUtilsTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Tests pin floating time.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testPinFloatingTime() throws Exception {
    TimeZone tz1 = TIMEZONE_REGISTRY.getTimeZone("America/Chicago");
   
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new Date("20070101"), tz1).toString());
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"), tz1).toString());
    
    
    TimeZone tz2 = TIMEZONE_REGISTRY.getTimeZone("America/Los_Angeles");
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new Date("20070101"), tz1).toString());
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"), tz1).toString());

    Assert.assertTrue(ICalendarUtils.pinFloatingTime(
            new Date("20070101"), tz1).before(
            ICalendarUtils.pinFloatingTime(new Date("20070101"),
                    tz2)));
    Assert.assertTrue(ICalendarUtils.pinFloatingTime(
            new DateTime("20070101T000000"), tz1).before(
            ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"),
                    tz2)));
}
 
Example #11
Source File: CalendarEntry.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * @param rule
 * @return date of recurrence end
 */
public Date getRecurrenceEndDate() {
    final TimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID());

    if (recurrenceRule != null) {
        try {
            final Recur recur = new Recur(recurrenceRule);
            final Date dUntil = recur.getUntil();
            final DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
            if (dtUntil != null) {
                dtUntil.setTimeZone(tz);
                return dtUntil;
            }
        } catch (final ParseException e) {
            log.error("cannot restore recurrence rule", e);
        }
    }

    return null;
}
 
Example #12
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets date property value
 * @param prop The date property.
 * @param date The date.
 */
protected void setDatePropertyValue(DateProperty prop, Date date) {
    if (prop == null) {
        return;
    }
    Value value = (Value) prop.getParameters()
            .getParameter(Parameter.VALUE);
    if (value != null) {
        prop.getParameters().remove(value);
    }

    // Add VALUE=DATE for Date values, otherwise
    // leave out VALUE=DATE-TIME because it is redundant
    if (!(date instanceof DateTime)) {
        prop.getParameters().add(Value.DATE);
    }
}
 
Example #13
Source File: EventStampInterceptor.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private String fromDateToStringNoTimezone(Date date) {
    if(date==null) {
        return null;
    }
    
    if(date instanceof DateTime) {
        DateTime dt = (DateTime) date;
        // If DateTime has a timezone, then convert to UTC before
        // serializing as String.
        if(dt.getTimeZone()!=null) {
            // clone instance first to prevent changes to original instance
            DateTime copy = new DateTime(dt);
            copy.setUtc(true);
            return copy.toString();
        } else {
            return dt.toString();
        }
    } else {
        return date.toString();
    }
}
 
Example #14
Source File: EventResource.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * @param recurIdList
 * @param iterator  The Data in Iterator should be Date or DateTime
 */
public void removeRecurIDListbyDate(ArrayList<String> recurIdList, DateList exDates) {
    String sDateTime;
    Iterator iterator = exDates.iterator();
    while (iterator.hasNext()) {
        Date exDate = (Date)iterator.next();
        if(exDate instanceof DateTime){
            ((DateTime) exDate).setUtc(true);
        }
        // exDates must have same type with value
        sDateTime = exDate.toString();
        int positionT = sDateTime.indexOf("T");
        if(positionT>0){
            sDateTime = sDateTime.substring(0, positionT);
        }
        recurIdList.remove(sDateTime);
    }
}
 
Example #15
Source File: ModificationUidImpl.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Converts an ical4j Date instance to a string representation.  If the instance
 * is a DateTime and has a timezone, then the string representation will be
 * UTC.
 * @param date date to format
 * @return string representation of date
 */
public static String fromDateToStringNoTimezone(Date date) {
    if(date==null) {
        return null;
    }
    
    if(date instanceof DateTime) {
        DateTime dt = (DateTime) date;
        // If DateTime has a timezone, then convert to UTC before
        // serializing as String.
        if(dt.getTimeZone()!=null) {
            // clone instance first to prevent changes to original instance
            DateTime copy = new DateTime(dt);
            copy.setUtc(true);
            return copy.toString();
        } else {
            return dt.toString();
        }
    } else {
        return date.toString();
    }
}
 
Example #16
Source File: ThisAndFutureHelper.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private void modifyOldSeries(NoteItem oldSeries, Date lastRecurrenceId) {
    EventStamp event = StampUtils.getEventStamp(oldSeries);
  
    // We set the end date to 1 second before the begining of the next day
    java.util.Calendar untilDateCalendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    untilDateCalendar.setTime(lastRecurrenceId);
    untilDateCalendar.add(java.util.Calendar.DAY_OF_MONTH, -1);
    untilDateCalendar.set(java.util.Calendar.HOUR_OF_DAY, 23);
    untilDateCalendar.set(java.util.Calendar.MINUTE, 59);
    untilDateCalendar.set(java.util.Calendar.SECOND, 59);
    Date untilDate = Dates.getInstance(untilDateCalendar.getTime(), lastRecurrenceId);
    
    // UNTIL must be UTC according to spec
    if(untilDate instanceof DateTime) {
        ((DateTime) untilDate).setUtc(true);
    }
    List<Recur> recurs = event.getRecurrenceRules();
    for (Recur recur : recurs) {
        recur.setUntil(untilDate);
    }
    
    // TODO: Figure out what to do with RDATEs
}
 
Example #17
Source File: StandardItemFilterProcessorTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Tests event stamp time range query.
 * 
 * @throws Exception
 *             - if something is wrong this exception is thrown.
 */
@Test
public void testEventStampTimeRangeQuery() throws Exception {
    NoteItemFilter filter = new NoteItemFilter();
    EventStampFilter eventFilter = new EventStampFilter();
    Period period = new Period(new DateTime("20070101T100000Z"), new DateTime("20070201T100000Z"));
    eventFilter.setPeriod(period);
    eventFilter.setTimezone(registry.getTimeZone("America/Chicago"));

    CollectionItem parent = new HibCollectionItem();
    filter.setParent(parent);
    filter.getStampFilters().add(eventFilter);
    QueryImpl<Item> query = queryBuilder.buildQuery(filter);
    Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, "
            + "HibBaseEventStamp es where pd.primaryKey.collection=:parent and es.item=i "
            + "and ( (es.timeRangeIndex.isFloating=true and "
            + "es.timeRangeIndex.startDate < '20070201T040000' and "
            + "es.timeRangeIndex.endDate > '20070101T040000') or " + "(es.timeRangeIndex.isFloating=false and "
            + "es.timeRangeIndex.startDate < '20070201T100000Z' and "
            + "es.timeRangeIndex.endDate > '20070101T100000Z') or "
            + "(es.timeRangeIndex.startDate=es.timeRangeIndex.endDate and "
            + "(es.timeRangeIndex.startDate='20070101T040000' or "
            + "es.timeRangeIndex.startDate='20070101T100000Z')))", query.getQueryString());
}
 
Example #18
Source File: TimeRangeFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a TimeRangeFilter object from a DOM Element
 * @param element The DOM Element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException {        
    // Get start (must be present)
    String start =
        DomUtil.getAttribute(element, ATTR_CALDAV_START, null);
    if (start == null) {
        throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1);
    }
    
    DateTime trstart = new DateTime(start);
    if (! trstart.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1);
    }

    // Get end (must be present)
    String end =
        DomUtil.getAttribute(element, ATTR_CALDAV_END, null);        
    DateTime trend = end != null ? new DateTime(end) : getDefaultEndDate(trstart);
    
    if (! trend.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
    }

    setPeriod(new Period(trstart, trend));
    setTimezone(timezone);
}
 
Example #19
Source File: InstanceListTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests instance start before range.
 *
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testInstanceStartBeforeRange() throws Exception {

    Calendar calendar = getCalendar("recurring_with_exdates.ics");

    InstanceList instances = new InstanceList();

    // make sure startRange is after the startDate of an occurrence,
    // in this case the occurrence is at 20070529T101500Z
    DateTime start = new DateTime("20070529T110000Z");
    DateTime end = new DateTime("20070530T051500Z");

    addToInstanceList(calendar, instances, start, end);

    Assert.assertEquals(1, instances.size());

    Iterator<String> keys = instances.keySet().iterator();

    String key = null;
    Instance instance = null;

    key = keys.next();
    instance = (Instance) instances.get(key);

    Assert.assertEquals("20070529T101500Z", key);
    Assert.assertEquals("20070529T051500", instance.getStart().toString());
    Assert.assertEquals("20070529T061500", instance.getEnd().toString());
}
 
Example #20
Source File: InstanceListTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests all day reccuring with modes.
 *
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testAllDayRecurringWithMods() throws Exception {

    Calendar calendar = getCalendar("allday_weekly_recurring_with_mods.ics");

    InstanceList instances = new InstanceList();
    TimeZone tz = TIMEZONE_REGISTRY.getTimeZone("America/Chicago");
    instances.setTimezone(tz);

    DateTime start = new DateTime("20070101T090000Z");
    DateTime end = new DateTime("20070109T090000Z");

    addToInstanceList(calendar, instances, start, end);

    Assert.assertEquals(2, instances.size());

    Iterator<String> keys = instances.keySet().iterator();

    String key = null;
    Instance instance = null;

    key = keys.next();
    instance = (Instance) instances.get(key);

    Assert.assertEquals("20070101", key);
    Assert.assertEquals("20070101", instance.getStart().toString());
    Assert.assertEquals("20070102", instance.getEnd().toString());

    key = keys.next();
    instance = (Instance) instances.get(key);

    Assert.assertEquals("20070108", key);
    Assert.assertEquals("20070109", instance.getStart().toString());
    Assert.assertEquals("20070110", instance.getEnd().toString());
}
 
Example #21
Source File: HibernateTriageStatusQueryProcessorTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests get later collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetLaterCollection() throws Exception {
    CollectionItem calendar = (CollectionItem) contentDao.findItemByUid(CALENDAR_UID);
    TriageStatusQueryContext context =
        new TriageStatusQueryContext(TriageStatus.LABEL_LATER, new DateTime("20070601T000000Z"), null);
    Set<NoteItem> later = queryProcessor.processTriageStatusQuery(calendar, context);
    Assert.assertEquals(5, later.size());
    verifyItemInSet(later,NOTE_UID + "later");
    verifyItemInSet(later,"calendar2_1:20070605T101500Z");
    verifyItemInSet(later,"calendar2_3:20070601T081500Z");
    verifyItemInSet(later,"calendar2_1");
    verifyItemInSet(later,"calendar2_3");
}
 
Example #22
Source File: ICalendarUtilsTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests normalize UTC dateTime to date.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testNormalizeUTCDateTimeToDate() throws Exception {
    TimeZone tz = TIMEZONE_REGISTRY.getTimeZone("America/Chicago");
    
    DateTime dt = new DateTime("20070201T070000Z");
    
    Assert.assertEquals("20070201", ICalendarUtils.normalizeUTCDateTimeToDate(dt, tz).toString());
    
    tz = TIMEZONE_REGISTRY.getTimeZone("America/Los_Angeles");
    Assert.assertEquals("20070131", ICalendarUtils.normalizeUTCDateTimeToDate(dt, tz).toString());
    
    tz = TIMEZONE_REGISTRY.getTimeZone("Australia/Sydney");
    Assert.assertEquals("20070201", ICalendarUtils.normalizeUTCDateTimeToDate(dt, tz).toString());
}
 
Example #23
Source File: InstanceListTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests UTC Instance List all day event.
 *
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testUTCInstanceListAllDayEvent() throws Exception {

    Calendar calendar = getCalendar("allday_weekly_recurring.ics");

    InstanceList instances = new InstanceList();
    instances.setUTC(true);
    instances.setTimezone(TIMEZONE_REGISTRY.getTimeZone("America/Chicago"));

    DateTime start = new DateTime("20070103T090000Z");
    DateTime end = new DateTime("20070117T090000Z");

    addToInstanceList(calendar, instances, start, end);

    Assert.assertEquals(2, instances.size());

    Iterator<String> keys = instances.keySet().iterator();

    String key = null;
    Instance instance = null;

    key = keys.next();
    instance = (Instance) instances.get(key);

    Assert.assertEquals("20070108T060000Z", key);
    Assert.assertEquals("20070108T060000Z", instance.getStart().toString());
    Assert.assertEquals("20070109T060000Z", instance.getEnd().toString());

    key = keys.next();
    instance = (Instance) instances.get(key);

    Assert.assertEquals("20070115T060000Z", key);
    Assert.assertEquals("20070115T060000Z", instance.getStart().toString());
    Assert.assertEquals("20070116T060000Z", instance.getEnd().toString());
}
 
Example #24
Source File: RecurrenceExpanderTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests recurrence expander single occurance.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testRecurrenceExpanderSingleOccurrence() throws Exception {
    RecurrenceExpander expander = new RecurrenceExpander();
    Calendar calendar = getCalendar("floating_recurring4.ics");
    
    InstanceList instances = expander.getOcurrences(calendar, new DateTime("20080101T100000"),
                                                    new DateTime("20080101T100001"), null);
    
    Assert.assertEquals(1, instances.size());
}
 
Example #25
Source File: StandardTriageStatusQueryProcessor.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Get all instances that are occuring during a given point in time
 * @param note NoteItem
 * @param context TriageStatusQueryContext
 * @return Set<NoteItem>
 */
private Set<NoteItem>
    getNowFromRecurringNote(NoteItem note,
                            TriageStatusQueryContext context) {
    EventStamp eventStamp = StampUtils.getEventStamp(note);
    DateTime currentDate = new DateTime(context.getPointInTime()); 
    RecurrenceExpander expander = new RecurrenceExpander();
    HashSet<NoteItem> results = new HashSet<NoteItem>();
    
    // Get all occurrences that overlap current instance in time
    InstanceList occurrences = expander.getOcurrences(
            eventStamp.getEvent(), eventStamp.getExceptions(), currentDate,
            currentDate, context.getTimeZone());
    
    for(Instance instance: (Collection<Instance>) occurrences.values()) {
        // Not interested in modifications
        if(!instance.isOverridden()) {
            // add occurrence
            results.add(NoteOccurrenceUtil.createNoteOccurrence(instance.getRid(), note));
        } else {
            // return modification if it has no triage-status
            ModificationUid modUid = new ModificationUidImpl(note, instance.getRid());
            NoteItem mod = (NoteItem) contentDao.findItemByUid(modUid.toString());
            if(mod.getTriageStatus()==null || mod.getTriageStatus().getCode()==null) {
                results.add(mod);
            }
        }
    }
    
    return results;
}
 
Example #26
Source File: StandardTriageStatusQueryProcessor.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate and return the latest ocurring instance or modification for the 
 * specified master event and date range.
 * The instance must end before the end of the range.
 * If the latest instance is a modification, then the modification must
 * have a triageStatus of DONE
 *
 * @param event Eventstamp
 * @param rangeStart Date
 * @param rangeEnd Date
 * @param timezone Timezone
 * @return NoteItem
 */
private NoteItem getLatestInstanceOrModification(EventStamp event, Date rangeStart, Date rangeEnd,
        TimeZone timezone) {
    NoteItem note = (NoteItem) event.getItem();
    RecurrenceExpander expander = new RecurrenceExpander();
    
    InstanceList instances = expander.getOcurrences(event.getEvent(), event.getExceptions(),
            new DateTime(rangeStart), new DateTime(rangeEnd), timezone);

    // Find the latest occurrence that ends before the end of the range
    while (instances.size() > 0) {
        String lastKey = (String) instances.lastKey();
        Instance instance = (Instance) instances.remove(lastKey);
        if (instance.getEnd().before(rangeEnd)) {
            if(instance.isOverridden()) {
                ModificationUid modUid = new ModificationUidImpl(note, instance.getRid());
                NoteItem mod = (NoteItem) contentDao.findItemByUid(modUid.toString());
                // shouldn't happen, but log and continue if it does
                if(mod==null) {
                    LOG.error("no modification found for uid: {}", modUid.toString());
                    continue;
                }
                TriageStatus status = mod.getTriageStatus();
                if(status==null || status.getCode().equals(TriageStatus.CODE_DONE)) {
                    return mod;
                }
            } else {
                return NoteOccurrenceUtil.createNoteOccurrence(instance.getRid(), note);
            }
        }
            
    }

    return null;
}
 
Example #27
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests limit floating recurrence set.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitFloatingRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_float_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(3, calendar.getComponents().getComponents("VEVENT").size());
    
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060102T170000");
    DateTime end = new DateTime("20060104T170000");
    
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
    // Make sure 2nd override is dropped
    ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);        
    for(VEvent c : vevents) {            
        Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
    }   
}
 
Example #28
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests limit recurrence set.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(5, calendar.getComponents().getComponents("VEVENT").size());
    
    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060104T010000", tz);
    DateTime end = new DateTime("20060106T010000", tz);
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    ComponentList<CalendarComponent> comps = filterCal.getComponents();
    Assert.assertEquals(3, comps.getComponents("VEVENT").size());
    Assert.assertEquals(1, comps.getComponents("VTIMEZONE").size());
    
    // Make sure 3rd and 4th override are dropped

    ComponentList<CalendarComponent> events = comps.getComponents("VEVENT");
    for(CalendarComponent c : events) {            
        Assert.assertNotSame("event 6 changed 3",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 4",c.getProperties().getProperty("SUMMARY").getValue());
    }
}
 
Example #29
Source File: ICalUtils.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
static DateTime toDateTime(ZonedDateTime zonedDateTime, TimeZoneRegistry registry) {
    final String tzId = zonedDateTime.getZone().getId();
    final TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
    // workaround for https://github.com/apache/camel-quarkus/issues/838
    final DateTime result = new DateTime();
    result.setTimeZone(timezone);
    result.setTime(zonedDateTime.toInstant().toEpochMilli());
    // To reproduce https://github.com/apache/camel-quarkus/issues/838 comment the above, enable the following
    // and remove the TZ from DTSTART and DTEND in src/test/resources/test.ics
    // final DateTime result = new DateTime(zonedDateTime.toInstant().toEpochMilli());
    return result;
}
 
Example #30
Source File: EventResource.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * @param recurIdList
 * @param iterator      The Data in Iterator should be DateTime
 */
public void fillRecurIDListbyDateTime(ArrayList<String> recurIdList, DateList recurDates) {
    String sDateTime;
    Iterator iterator = recurDates.iterator();
    while (iterator.hasNext()) {
        DateTime dateTime = (DateTime)iterator.next();
        dateTime.setUtc(true);
        sDateTime = dateTime.toString();
        recurIdList.add(sDateTime);
    }
}