List of usage examples for org.joda.time Interval Interval
public Interval(Object interval, Chronology chronology)
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year.//ww w .j a v a2s. c o m * * @param targetMonth * @param targetDay * @param gregorianYear * @param targetChrono * @return the list of gregorian dates. */ private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay, int gregorianYear, Chronology targetChrono) { Set<LocalDate> holidays = new HashSet<LocalDate>(); LocalDate firstGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.JANUARY, 1, ISOChronology.getInstance()); LocalDate lastGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.DECEMBER, 31, ISOChronology.getInstance()); LocalDate firstTargetDate = new LocalDate(firstGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); LocalDate lastTargetDate = new LocalDate(lastGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); Interval interv = new Interval(firstTargetDate.toDateTimeAtStartOfDay(), lastTargetDate.plusDays(1).toDateTimeAtStartOfDay()); int targetYear = firstTargetDate.getYear(); for (; targetYear <= lastTargetDate.getYear();) { LocalDate d = new LocalDate(targetYear, targetMonth, targetDay, targetChrono); if (interv.contains(d.toDateTimeAtStartOfDay())) { holidays.add(convertToISODate(d)); } targetYear++; } return holidays; }
From source file:com.knewton.mapreduce.example.StudentEventAbstractMapper.java
License:Apache License
/** * Sets up a DateTime interval for excluding student events. When start time is not set then it * defaults to the beginning of time. If end date is not specified then it defaults to * "the end of time".//w ww .ja v a 2s. c o m */ private void setupTimeRange(Configuration conf) { DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_STRING_FORMAT).withZoneUTC(); String startDateStr = conf.get(PropertyConstants.START_DATE.txt); String endDateStr = conf.get(PropertyConstants.END_DATE.txt); // No need to instantiate timeRange. if (startDateStr == null && endDateStr == null) { return; } DateTime startDate; if (startDateStr != null) { startDate = dtf.parseDateTime(startDateStr); } else { startDate = new DateTime(0).year().withMinimumValue().withZone(DateTimeZone.UTC); } DateTime endDate; if (endDateStr != null) { endDate = dtf.parseDateTime(endDateStr); } else { endDate = new DateTime(0).withZone(DateTimeZone.UTC).year().withMaximumValue(); } this.timeRange = new Interval(startDate, endDate); }
From source file:com.knewton.mapreduce.StudentEventAbstractMapper.java
License:Apache License
/** * Sets up a DateTime interval for excluding student events. When start time is not set then it * defaults to the beginning of time. If end date is not specified then it defaults to * "the end of time"./*from w w w . ja v a 2 s.co m*/ * * @param conf */ private void setupTimeRange(Configuration conf) { DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_STRING_FORMAT).withZoneUTC(); String startDateStr = conf.get(START_DATE_PARAMETER_NAME); String endDateStr = conf.get(END_DATE_PARAMETER_NAME); // No need to instantiate timeRange. if (startDateStr == null && endDateStr == null) { return; } DateTime startDate; if (startDateStr != null) { startDate = dtf.parseDateTime(startDateStr); } else { startDate = new DateTime(Long.MIN_VALUE + ONE_DAY_IN_MILLIS).withZone(DateTimeZone.UTC); } DateTime endDate; if (endDateStr != null) { endDate = dtf.parseDateTime(endDateStr); } else { endDate = new DateTime(Long.MAX_VALUE - ONE_DAY_IN_MILLIS).withZone(DateTimeZone.UTC); } this.timeRange = new Interval(startDate, endDate); }
From source file:com.linkedin.pinot.common.metadata.segment.SegmentZKMetadata.java
License:Apache License
/** * NOTE: should be called after setting start and end time. *//*from w ww .j av a 2s. c om*/ public void setTimeUnit(@Nonnull TimeUnit timeUnit) { _timeUnit = timeUnit; _timeGranularity = new Duration(_timeUnit.toMillis(1)); // For consuming segment, end time might not be set if (_startTime >= 0 && _startTime <= _endTime) { _timeInterval = new Interval(_timeUnit.toMillis(_startTime), _timeUnit.toMillis(_endTime)); } }
From source file:com.linkedin.pinot.controller.validation.ValidationManager.java
License:Apache License
/** * Computes a list of missing intervals, given a list of existing intervals and the expected frequency of the * intervals./*from ww w .j av a 2s. c o m*/ * * @param segmentIntervals The list of existing intervals * @param frequency The expected interval frequency * @return The list of missing intervals */ public static List<Interval> computeMissingIntervals(List<Interval> segmentIntervals, Duration frequency) { // Sanity check for freuency if (frequency == null) { return Collections.emptyList(); } // Default segment granularity to day level if its small than hours. if (frequency.getMillis() < Duration.standardHours(1).getMillis()) { frequency = Duration.standardDays(1); } // If there are less than two segments, none can be missing if (segmentIntervals.size() < 2) { return Collections.emptyList(); } // Sort the intervals by ascending starting time List<Interval> sortedSegmentIntervals = new ArrayList<Interval>(segmentIntervals); Collections.sort(sortedSegmentIntervals, new Comparator<Interval>() { @Override public int compare(Interval first, Interval second) { if (first.getStartMillis() < second.getStartMillis()) return -1; else if (second.getStartMillis() < first.getStartMillis()) return 1; return 0; } }); // Find the minimum starting time and maximum ending time final long startTime = sortedSegmentIntervals.get(0).getStartMillis(); long endTime = Long.MIN_VALUE; for (Interval sortedSegmentInterval : sortedSegmentIntervals) { if (endTime < sortedSegmentInterval.getEndMillis()) { endTime = sortedSegmentInterval.getEndMillis(); } } final long frequencyMillis = frequency.getMillis(); int lastEndIntervalCount = 0; List<Interval> missingIntervals = new ArrayList<Interval>(10); for (Interval segmentInterval : sortedSegmentIntervals) { int startIntervalCount = (int) ((segmentInterval.getStartMillis() - startTime) / frequencyMillis); int endIntervalCount = (int) ((segmentInterval.getEndMillis() - startTime) / frequencyMillis); // If there is at least one complete missing interval between the end of the previous interval and the start of // the current interval, then mark the missing interval(s) as missing if (lastEndIntervalCount < startIntervalCount - 1) { for (int missingIntervalIndex = lastEndIntervalCount + 1; missingIntervalIndex < startIntervalCount; ++missingIntervalIndex) { missingIntervals.add(new Interval(startTime + frequencyMillis * missingIntervalIndex, startTime + frequencyMillis * (missingIntervalIndex + 1) - 1)); } } lastEndIntervalCount = Math.max(lastEndIntervalCount, endIntervalCount); } return missingIntervals; }
From source file:com.linkedin.pinot.core.realtime.impl.RealtimeSegmentImpl.java
License:Apache License
@Override public Interval getTimeInterval() { DateTime start = timeConverter.getDataTimeFrom(minTimeVal); DateTime end = timeConverter.getDataTimeFrom(maxTimeVal); return new Interval(start, end); }
From source file:com.linkedin.pinot.core.segment.index.SegmentMetadataImpl.java
License:Apache License
private void setTimeIntervalAndGranularity() { if (_segmentMetadataPropertiesConfiguration.containsKey(V1Constants.MetadataKeys.Segment.SEGMENT_START_TIME) && _segmentMetadataPropertiesConfiguration .containsKey(V1Constants.MetadataKeys.Segment.SEGMENT_END_TIME) && _segmentMetadataPropertiesConfiguration .containsKey(V1Constants.MetadataKeys.Segment.TIME_UNIT)) { try {//from ww w . j a v a 2s . c om TimeUnit segmentTimeUnit = TimeUtils .timeUnitFromString(_segmentMetadataPropertiesConfiguration.getString(TIME_UNIT)); _timeGranularity = new Duration(segmentTimeUnit.toMillis(1)); String startTimeString = _segmentMetadataPropertiesConfiguration .getString(V1Constants.MetadataKeys.Segment.SEGMENT_START_TIME); String endTimeString = _segmentMetadataPropertiesConfiguration .getString(V1Constants.MetadataKeys.Segment.SEGMENT_END_TIME); _timeInterval = new Interval(segmentTimeUnit.toMillis(Long.parseLong(startTimeString)), segmentTimeUnit.toMillis(Long.parseLong(endTimeString))); } catch (Exception e) { LOGGER.warn("Caught exception while setting time interval and granularity", e); _timeInterval = null; _timeGranularity = null; } } }
From source file:com.manydesigns.portofino.calendar.AbstractDay.java
License:Open Source License
public AbstractDay(DateMidnight dayStart, DateMidnight dayEnd) { this.dayStart = dayStart; this.dayEnd = dayEnd; dayInterval = new Interval(dayStart, dayEnd); AbstractMonthView.logger.debug("Day interval: {}", dayInterval); }
From source file:com.manydesigns.portofino.calendar.AbstractMonth.java
License:Open Source License
public AbstractMonth(DateMidnight referenceDateMidnight) { logger.debug("Initializing month"); this.referenceDateMidnight = referenceDateMidnight; logger.debug("Reference date midnight: {}", referenceDateMidnight); monthStart = referenceDateMidnight.withDayOfMonth(1); monthEnd = monthStart.plusMonths(1); monthInterval = new Interval(monthStart, monthEnd); logger.debug("Month interval: {}", monthInterval); daysCount = Days.daysIn(monthInterval).getDays(); logger.debug("Initializing {} days", daysCount); days = createDaysArray(daysCount);//from w w w.j a v a 2 s .c o m DateMidnight dayStart = monthStart; for (int i = 0; i < daysCount; i++) { DateMidnight dayEnd = dayStart.plusDays(1); days[i] = createDay(dayStart, dayEnd); // advance to next day dayStart = dayEnd; } }
From source file:com.manydesigns.portofino.calendar.AbstractMonthView.java
License:Open Source License
public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) { logger.debug("Initializing month"); this.referenceDateTime = referenceDateTime; logger.debug("Reference date time: {}", referenceDateTime); this.firstDayOfWeek = firstDayOfWeek; logger.debug("First day of week: {}", firstDayOfWeek); referenceDateMidnight = new DateMidnight(referenceDateTime); referenceYear = referenceDateTime.getYear(); referenceMonth = referenceDateTime.getMonthOfYear(); monthStart = referenceDateMidnight.withDayOfMonth(1); monthEnd = monthStart.plusMonths(1); monthInterval = new Interval(monthStart, monthEnd); monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek); monthViewEnd = monthViewStart.plusWeeks(6); monthViewInterval = new Interval(monthViewStart, monthViewEnd); logger.debug("Month view start: {}", monthViewStart); logger.debug("Initializing weeks"); weeks = createWeeksArray(6);//w w w .jav a 2s . c om DateMidnight weekStart = monthViewStart; for (int i = 0; i < weeks.length; i++) { DateMidnight weekEnd = weekStart.plusWeeks(1); weeks[i] = createWeek(weekStart, weekEnd); weekStart = weekEnd; } }