List of usage examples for org.joda.time Interval Interval
public Interval(Object interval, Chronology chronology)
From source file:com.google.sampling.experiential.server.DSQueryBuilder.java
License:Open Source License
private static Interval getXWeeksAgo(int weeksAgo, DateTimeZone clientTimeZone) { DateTime lastMondayAfter = getMondayAfterWeekEnclosing(getDayLastWeek(clientTimeZone)); DateTime xMondaysAfterAgo = lastMondayAfter.minusWeeks(weeksAgo); DateTime xMondaysAgo = xMondaysAfterAgo.minusWeeks(1); return new Interval(xMondaysAgo, lastMondayAfter); }
From source file:com.google.sampling.experiential.server.DSQueryBuilder.java
License:Open Source License
private static Interval getWeekEnclosing(DateTime today) { DateTime monday = getMondayOfWeekEnclosing(today); DateTime nextMonday = getMondayAfterWeekEnclosing(today); return new Interval(monday, nextMonday); }
From source file:com.google.sampling.experiential.server.EventMatcher.java
License:Open Source License
private boolean compareDateRange(String range, Event event) { Iterable<String> iterable = Splitter.on("-").split(range); Iterator<String> iter = iterable.iterator(); if (!iter.hasNext()) { throw new IllegalArgumentException("Illformed Date Range: " + range); }//from w w w .j a v a 2 s . c o m String firstDate = iter.next(); String secondDate = null; if (iter.hasNext()) { secondDate = iter.next(); } DateMidnight startDate = newDateMidnightFromString(firstDate); DateMidnight endDate = null; if (secondDate != null && !secondDate.isEmpty()) { endDate = newDateMidnightFromString(secondDate); } else { endDate = startDate.plusDays(1); } Interval r2 = new Interval(startDate, endDate); Date eventDate = event.getWhen(); if (eventDate == null) { return false; } DateMidnight eventDateMidnight = new DateMidnight(eventDate.getTime()); return r2.contains(eventDateMidnight); }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
@Override public LocalDate generateNextRepaymentDate(final LocalDate lastRepaymentDate, final LoanApplicationTerms loanApplicationTerms, boolean isFirstRepayment, final HolidayDetailDTO holidayDetailDTO) { final LocalDate firstRepaymentPeriodDate = loanApplicationTerms .getCalculatedRepaymentsStartingFromLocalDate(); LocalDate dueRepaymentPeriodDate = null; Calendar currentCalendar = loanApplicationTerms.getLoanCalendar(); if (isFirstRepayment && firstRepaymentPeriodDate != null) { dueRepaymentPeriodDate = firstRepaymentPeriodDate; } else {// www. ja v a 2 s. c o m dueRepaymentPeriodDate = getRepaymentPeriodDate(loanApplicationTerms.getRepaymentPeriodFrequencyType(), loanApplicationTerms.getRepaymentEvery(), lastRepaymentDate, null, null); dueRepaymentPeriodDate = CalendarUtils.adjustDate(dueRepaymentPeriodDate, loanApplicationTerms.getSeedDate(), loanApplicationTerms.getRepaymentPeriodFrequencyType()); if (currentCalendar != null) { // If we have currentCalendar object, this means there is a // calendar associated with // the loan, and we should use it in order to calculate next // repayment CalendarHistory calendarHistory = null; CalendarHistoryDataWrapper calendarHistoryDataWrapper = loanApplicationTerms .getCalendarHistoryDataWrapper(); if (calendarHistoryDataWrapper != null) { calendarHistory = loanApplicationTerms.getCalendarHistoryDataWrapper() .getCalendarHistory(dueRepaymentPeriodDate); } // get the start date from the calendar history LocalDate seedDate = null; String reccuringString = null; if (calendarHistory == null) { seedDate = currentCalendar.getStartDateLocalDate(); reccuringString = currentCalendar.getRecurrence(); } else { seedDate = calendarHistory.getStartDateLocalDate(); reccuringString = calendarHistory.getRecurrence(); } dueRepaymentPeriodDate = CalendarUtils.getNewRepaymentMeetingDate(reccuringString, seedDate, lastRepaymentDate.plusDays(1), loanApplicationTerms.getRepaymentEvery(), CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType( loanApplicationTerms.getLoanTermPeriodFrequencyType()), holidayDetailDTO.getWorkingDays(), loanApplicationTerms.isSkipRepaymentOnFirstDayofMonth(), loanApplicationTerms.getNumberOfdays()); } } if (currentCalendar == null && holidayDetailDTO.getWorkingDays().getExtendTermForRepaymentsOnHolidays()) { boolean repaymentDateIsOnHoliday = false; // compile the list of holidays into Intervals to see if this date lands on a holiday final List<Interval> holidayInterval = new ArrayList<>(); for (Holiday holiday : holidayDetailDTO.getHolidays()) { holidayInterval.add(new Interval(holiday.getFromDateLocalDate().toDateTimeAtStartOfDay(), holiday.getToDateLocalDate().toDateTime(LocalTime.parse("23:59:59")))); } while (intervalListContainsDate(holidayInterval, dueRepaymentPeriodDate)) { LocalDate previousDate = dueRepaymentPeriodDate; dueRepaymentPeriodDate = getRepaymentPeriodDate( loanApplicationTerms.getRepaymentPeriodFrequencyType(), loanApplicationTerms.getRepaymentEvery(), dueRepaymentPeriodDate, loanApplicationTerms.getNthDay(), loanApplicationTerms.getWeekDayType()); } } return dueRepaymentPeriodDate; }
From source file:com.hamdikavak.humanmobility.modeling.helpers.LocationTraceHelper.java
License:Open Source License
/** * Cleans traces that shared within a sort period of time from the same place * @param traces list of traces. location id of traces has to be set. * @param duration threshold length to identify repeated consequent traces * @return a list of cleaned traces.//from ww w. ja v a2s . c om */ public List<ExtendedLocationTrace> cleanRepeatedTraces(List<ExtendedLocationTrace> traces, Duration duration) { // check whether we have enough number of traces if (traces == null || traces.size() < 2) { return traces; } // at this point, we have at least two traces Iterator<ExtendedLocationTrace> traceIterator = traces.iterator(); ExtendedLocationTrace firstTrace = traceIterator.next(); // auto-assign first trace ExtendedLocationTrace secondTrace = null; // to be assigned while (traceIterator.hasNext()) { // get the next item secondTrace = traceIterator.next(); DateTime firstDate = firstTrace.getUTCTime(); DateTime secondDate = secondTrace.getUTCTime(); // calculate time interval between the two Interval interval = new Interval(firstDate, secondDate); // the following if statement checks whether both traces report the same place // and their inter-event duration is shorter than our threshold duration if (firstTrace.getLocationId() == secondTrace.getLocationId() && interval.toDuration().isShorterThan(duration)) { // this means the user reported his/her location shortly after one another. // we delete this record. traceIterator.remove(); } else { // this means, didn't report from the same location within a certain time after the first report. firstTrace = secondTrace; } } return traces; }
From source file:com.hamdikavak.humanmobility.modeling.helpers.LocationTraceHelper.java
License:Open Source License
/** * /*from ww w. j a v a 2 s . c o m*/ * Cleans traces that are shared within a given sort period of time from a * given nearby location distance. This method is different from * {@code LocationTraceHelper.cleanRepeatedTraces} method in a way that this * doesn't require pre-assigned location ids to traces. * * @param traces list of traces. * @param distance threshold spatial distance to identify repeated consequent traces * @param duration threshold length to identify repeated consequent traces * @return a list of cleaned traces. */ public List<ExtendedLocationTrace> cleanRepeatedTracesByDistance(List<ExtendedLocationTrace> traces, DistanceWithUnit distance, Duration duration) { // check whether we have enough number of traces if (traces == null || traces.size() < 2) { return traces; } // at this point, we have at least two traces Iterator<ExtendedLocationTrace> traceIterator = traces.iterator(); ExtendedLocationTrace firstTrace = traceIterator.next(); // auto-assign first trace ExtendedLocationTrace secondTrace = null; // to be assigned while (traceIterator.hasNext()) { // get the next item secondTrace = traceIterator.next(); DateTime firstDate = firstTrace.getUTCTime(); DateTime secondDate = secondTrace.getUTCTime(); // calculate time interval between the two Interval interval = new Interval(firstDate, secondDate); // the following if statement checks whether both traces report within a short distance // and their inter-event duration is shorter than our threshold duration double calculatedDistance = spatialOperation.calculateDistance(firstTrace.getCoordinate(), secondTrace.getCoordinate(), SpatialDistanceUnit.Meter); DistanceWithUnit calculatedDistanceObject = new DistanceWithUnit(calculatedDistance, SpatialDistanceUnit.Meter); if (calculatedDistanceObject.isShortherThan(distance) && interval.toDuration().isShorterThan(duration)) { // this means the user reported his/her location shortly after one another. // we delete this record. traceIterator.remove(); } else { // this means, didn't report from the same location within a certain time after the first report. firstTrace = secondTrace; } } return traces; }
From source file:com.helger.datetime.holiday.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year./*from w w w .j ava 2s . c o m*/ * * @param nTargetMonth * Target month * @param nTargetDay * Target day * @param nGregorianYear * Gregorian year * @param aTargetChronoUTC * Target chronology * @return the list of gregorian dates. */ @Nonnull public static Set<LocalDate> getDatesFromChronologyWithinGregorianYear(final int nTargetMonth, final int nTargetDay, final int nGregorianYear, final Chronology aTargetChronoUTC) { final Set<LocalDate> aHolidays = new HashSet<LocalDate>(); final LocalDate aFirstGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.JANUARY, 1); final LocalDate aLastGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.DECEMBER, 31); final LocalDate aFirstTargetDate = new LocalDate( aFirstGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(), aTargetChronoUTC); final LocalDate aLastTargetDate = new LocalDate( aLastGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(), aTargetChronoUTC); final Interval aInterv = new Interval( aFirstTargetDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()), aLastTargetDate.plusDays(1).toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC())); for (int nTargetYear = aFirstTargetDate.getYear(); nTargetYear <= aLastTargetDate .getYear(); ++nTargetYear) { final LocalDate aLocalDate = new LocalDate(nTargetYear, nTargetMonth, nTargetDay, aTargetChronoUTC); if (aInterv.contains(aLocalDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()))) { aHolidays.add(convertToGregorianDate(aLocalDate)); } } return aHolidays; }
From source file:com.helger.datetime.period.DateTimePeriod.java
License:Apache License
@Nonnull public Interval getAsInterval() { if (!canConvertToInterval()) throw new IllegalStateException("Cannot convert to an Interval!"); return new Interval(getStart(), getEnd()); }
From source file:com.inferlytics.druidlet.helper.QueryCreationHelper.java
License:Open Source License
public static Query getGroupByQuery() { List<DimFilter> filters = new ArrayList<DimFilter>(); filters.add(DimFilters.dimEquals("report", "URLTransaction")); filters.add(DimFilters.dimEquals("pool", "r1cart")); filters.add(DimFilters.dimEquals("metric", "Duration")); return GroupByQuery.builder().setDataSource("test") .setQuerySegmentSpec(QuerySegmentSpecs.create(new Interval(0, new DateTime().getMillis()))) .setGranularity(QueryGranularity.NONE).addDimension("URL") .addAggregator(new LongSumAggregatorFactory("agg_count", "agg_count")) .addAggregator(new DoubleMaxAggregatorFactory("agg_max", "agg_max")) .addAggregator(new DoubleMinAggregatorFactory("agg_min", "agg_min")) .addAggregator(new DoubleSumAggregatorFactory("agg_sum", "agg_sum")) .setDimFilter(DimFilters.and(filters)).build(); }
From source file:com.inferlytics.druidlet.helper.QueryCreationHelper.java
License:Open Source License
public static Query getTopNQuery() { List<DimFilter> filters = new ArrayList<DimFilter>(); filters.add(DimFilters.dimEquals("report", "URLTransaction")); filters.add(DimFilters.dimEquals("pool", "r1cart")); filters.add(DimFilters.dimEquals("metric", "Duration")); return new TopNQueryBuilder().threshold(5).metric("agg_count").dataSource("test") .intervals(QuerySegmentSpecs.create(new Interval(0, new DateTime().getMillis()))) .granularity(QueryGranularity.NONE).dimension("colo") .aggregators(Arrays.asList(new LongSumAggregatorFactory("agg_count", "agg_count"), new DoubleMaxAggregatorFactory("agg_max", "agg_max"), new DoubleMinAggregatorFactory("agg_min", "agg_min"), new DoubleSumAggregatorFactory("agg_sum", "agg_sum"))) .filters(DimFilters.and(filters)).build(); }