public boolean checkMoment(Date date) { if (calendar != null) { Period period = new Period(new DateTime(date), new Dur(0, 0, 0, 0)); Predicate<CalendarComponent> periodRule = new PeriodRule<>(period); Filter<CalendarComponent> filter = new Filter<>(new Predicate[] {periodRule}, Filter.MATCH_ANY); Collection<CalendarComponent> events = filter.filter(calendar.getComponents(CalendarComponent.VEVENT)); if (events != null && !events.isEmpty()) { return true; } } return false; }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add((Object) new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** * Parses the specified string representation to create a list of periods. * * @param aValue * a string representation of a list of periods * @throws ParseException * thrown when an invalid string representation of a period list * is specified */ public PeriodList(final String aValue) throws ParseException { this(); final StringTokenizer t = new StringTokenizer(aValue, ","); while (t.hasMoreTokens()) { add(new Period(t.nextToken())); } }
/** Merge in a period * * @param start * @param end * @throws CalFacadeException */ public void addPeriod(final DateTime start, final DateTime end) throws CalFacadeException { Period p; if (emitDurations) { p = new Period(start, new Dur(start, end)); } else { p = new Period(start, end); } addPeriod(p); }
/** * * @param dtStart The timerange start. * @param dtEnd The timerange end. */ public TimeRangeFilter(DateTime dtStart, DateTime dtEnd) { if (!dtStart.isUtc()) { throw new IllegalArgumentException("timerange start must be UTC"); } if (!dtEnd.isUtc()) { throw new IllegalArgumentException("timerange start must be UTC"); } Period period = new Period(dtStart, dtEnd); setPeriod(period); }
/** * * @param dtStart The timerange start. * @param dtEnd The timerange end. */ public TimeRangeFilter(DateTime dtStart, DateTime dtEnd) { if (!dtStart.isUtc()) { throw new IllegalArgumentException("timerange start must be UTC"); } if (!dtEnd.isUtc()) { throw new IllegalArgumentException("timerange start must be UTC"); } Period period = new Period(dtStart, dtEnd); setPeriod(period); }
/** * Matches events that occur in a given time-range. * @param start range start * @param end range end */ public void setTimeRange(Date start, Date end) { dstart = utc(start); dend = utc(end); fstart = start; fend = end; updateFloatingTimes(); period = new Period(dstart, dend); }
/** * Matches events that occur in a given time-range. * @param start range start * @param end range end */ public void setTimeRange(Date start, Date end) { dstart = utc(start); dend = utc(end); fstart = start; fend = end; updateFloatingTimes(); period = new Period(dstart, dend); }
/** * Unit tests for {@link Period#isEmpty()}. */ public void testIsEmpty() { Calendar cal = Calendar.getInstance(); DateTime start = new DateTime(cal.getTime()); assertTrue(new Period(start, start).isEmpty()); assertTrue(new Period(start, java.time.Period.ZERO).isEmpty()); cal.add(Calendar.SECOND, 1); assertFalse(new Period(start, new DateTime(cal.getTime())).isEmpty()); assertFalse(new Period(start, java.time.Duration.ofSeconds(1)).isEmpty()); }
@Override public void visit(TemporalExpressions.DateRange expr) { if (this.state.isExcluded) { throw new IllegalStateException("iCalendar does not support excluded date ranges"); } org.apache.ofbiz.base.util.DateRange range = expr.getDateRange(); PeriodList periodList = new PeriodList(); periodList.add(new Period(new DateTime(range.start()), new DateTime(range.end()))); this.incDateList.add(new RDate(periodList)); }
private static Period findFreeBusyRange(ReportInfo info) throws CosmoDavException { Element tre = info.getContentElement(ELEMENT_CALDAV_TIME_RANGE, NAMESPACE_CALDAV); if (tre == null) { throw new BadRequestException("Expected " + QN_CALDAV_TIME_RANGE); } DateTime sdt = null; try { String start = DomUtil.getAttribute(tre, ATTR_CALDAV_START, null); sdt = new DateTime(start); } catch (ParseException e) { throw new BadRequestException("Attribute " + ATTR_CALDAV_START + " not parseable: " + e.getMessage()); } DateTime edt = null; try { String end = DomUtil.getAttribute(tre, ATTR_CALDAV_END, null); edt = new DateTime(end); } catch (ParseException e) { throw new BadRequestException("Attribute " + ATTR_CALDAV_END + " not parseable: " + e.getMessage()); } return new Period(sdt, edt); }
private static Period findFreeBusyRange(ReportInfo info) throws CosmoDavException { Element tre = info.getContentElement(ELEMENT_CALDAV_TIME_RANGE, NAMESPACE_CALDAV); if (tre == null) { throw new BadRequestException("Expected " + QN_CALDAV_TIME_RANGE); } DateTime sdt = null; try { String start = DomUtil.getAttribute(tre, ATTR_CALDAV_START, null); sdt = new DateTime(start); } catch (ParseException e) { throw new BadRequestException("Attribute " + ATTR_CALDAV_START + " not parseable: " + e.getMessage()); } DateTime edt = null; try { String end = DomUtil.getAttribute(tre, ATTR_CALDAV_END, null); edt = new DateTime(end); } catch (ParseException e) { throw new BadRequestException("Attribute " + ATTR_CALDAV_END + " not parseable: " + e.getMessage()); } return new Period(sdt, edt); }
public final void testPeriodListSort() { PeriodList periods = new PeriodList(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 25); periods.add(new Period(new DateTime(), new DateTime(cal.getTime() .getTime()))); periods.add(new Period(new DateTime(cal.getTime().getTime()), java.time.Duration.ofHours(2))); periods.add(new Period(new DateTime(), java.time.Duration.ofHours(2))); periods.add(new Period(new DateTime(), java.time.Duration.ofHours(1))); // log.info("Unsorted list: " + periods); // Collections.sort(periods); log.info("Sorted list: " + periods); }
/** * Unit tests for {@link PeriodList#normalise()}. */ public void testNormalise() { // test a list of periods consuming no time.. PeriodList periods = new PeriodList(); DateTime start = new DateTime(); periods.add(new Period(start, start)); DateTime start2 = new DateTime(); periods.add(new Period(start2, start2)); assertTrue(periods.normalise().isEmpty()); } }
/** * Test timezone functionality. */ public void testTimezone() { // TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance() // .createRegistry(); // TimeZone timezone = registry.getTimeZone("Australia/Melbourne"); PeriodList list = new PeriodList(true); java.util.Calendar cal = java.util.Calendar.getInstance(); for (int i = 0; i < 5; i++) { DateTime start = new DateTime(cal.getTime()); cal.add(Calendar.DAY_OF_YEAR, 1); DateTime end = new DateTime(cal.getTime()); list.add(new Period(start, end)); } log.info("Timezone test - period list: [" + list + "]"); list.forEach(p -> { assertTrue(p.getStart().isUtc()); assertTrue(p.getEnd().isUtc()); }); }
public FreeBusy build() { final FreeBusy fb = new FreeBusy(); fb.getParameters().add(FbType.FREE); final PeriodList periods = getConsumedTime(components, start, end); final DateRange range = new DateRange(start, end); // Add final consumed time to avoid special-case end-of-list processing periods.add(new Period(end, end)); DateTime lastPeriodEnd = new DateTime(start); // where no time is consumed set the last period end as the range start.. for (final Period period : periods) { // check if period outside bounds.. or period intersects with the end of the range.. if (range.contains(period) || (range.intersects(period) && period.getStart().after(range.getRangeStart()))) { // calculate duration between this period start and last period end.. final Duration freeDuration = new Duration(lastPeriodEnd, period.getStart()); if (new TemporalAmountComparator().compare(freeDuration.getDuration(), duration) >= 0) { fb.getPeriods().add(new Period(lastPeriodEnd, freeDuration.getDuration())); } } if (period.getEnd().after(lastPeriodEnd)) { lastPeriodEnd = period.getEnd(); } } return fb; } }
public FreeBusy build() { final FreeBusy fb = new FreeBusy(); fb.getParameters().add(FbType.FREE); final PeriodList periods = getConsumedTime(components, start, end); final DateRange range = new DateRange(start, end); // Add final consumed time to avoid special-case end-of-list processing periods.add(new Period(end, end)); DateTime lastPeriodEnd = new DateTime(start); // where no time is consumed set the last period end as the range start.. for (final Period period : periods) { // check if period outside bounds.. or period intersects with the end of the range.. if (range.contains(period) || (range.intersects(period) && period.getStart().after(range.getRangeStart()))) { // calculate duration between this period start and last period end.. final Duration freeDuration = new Duration(lastPeriodEnd, period.getStart()); if (new TemporalAmountComparator().compare(freeDuration.getDuration(), duration) >= 0) { fb.getPeriods().add(new Period(lastPeriodEnd, freeDuration.getDuration())); } } if (period.getEnd().after(lastPeriodEnd)) { lastPeriodEnd = period.getEnd(); } } return fb; } }