List of usage examples for org.joda.time Interval toDurationMillis
public long toDurationMillis()
From source file:org.apache.druid.indexing.common.task.CompactionTask.java
License:Apache License
@JsonCreator public CompactionTask(@JsonProperty("id") final String id, @JsonProperty("resource") final TaskResource taskResource, @JsonProperty("dataSource") final String dataSource, @JsonProperty("interval") @Nullable final Interval interval, @JsonProperty("segments") @Nullable final List<DataSegment> segments, @JsonProperty("dimensions") @Nullable final DimensionsSpec dimensions, @JsonProperty("dimensionsSpec") @Nullable final DimensionsSpec dimensionsSpec, @JsonProperty("metricsSpec") @Nullable final AggregatorFactory[] metricsSpec, @JsonProperty("segmentGranularity") @Nullable final Granularity segmentGranularity, @JsonProperty("targetCompactionSizeBytes") @Nullable final Long targetCompactionSizeBytes, @JsonProperty("tuningConfig") @Nullable final IndexTuningConfig tuningConfig, @JsonProperty("context") @Nullable final Map<String, Object> context, @JacksonInject ObjectMapper jsonMapper, @JacksonInject AuthorizerMapper authorizerMapper, @JacksonInject ChatHandlerProvider chatHandlerProvider, @JacksonInject RowIngestionMetersFactory rowIngestionMetersFactory, @JacksonInject CoordinatorClient coordinatorClient, @JacksonInject SegmentLoaderFactory segmentLoaderFactory, @JacksonInject RetryPolicyFactory retryPolicyFactory, @JacksonInject AppenderatorsManager appenderatorsManager) { super(getOrMakeId(id, TYPE, dataSource), null, taskResource, dataSource, context); Preconditions.checkArgument(interval != null || segments != null, "interval or segments should be specified"); Preconditions.checkArgument(interval == null || segments == null, "one of interval and segments should be null"); if (interval != null && interval.toDurationMillis() == 0) { throw new IAE("Interval[%s] is empty, must specify a nonempty interval", interval); }/*www .j a va 2 s . c o m*/ this.interval = interval; this.segments = segments; this.dimensionsSpec = dimensionsSpec == null ? dimensions : dimensionsSpec; this.metricsSpec = metricsSpec; this.segmentGranularity = segmentGranularity; this.targetCompactionSizeBytes = targetCompactionSizeBytes; this.tuningConfig = tuningConfig; this.jsonMapper = jsonMapper; this.segmentProvider = segments == null ? new SegmentProvider(dataSource, interval) : new SegmentProvider(segments); this.partitionConfigurationManager = new PartitionConfigurationManager(targetCompactionSizeBytes, tuningConfig); this.authorizerMapper = authorizerMapper; this.chatHandlerProvider = chatHandlerProvider; this.rowIngestionMetersFactory = rowIngestionMetersFactory; this.coordinatorClient = coordinatorClient; this.segmentLoaderFactory = segmentLoaderFactory; this.retryPolicyFactory = retryPolicyFactory; this.appenderatorsManager = appenderatorsManager; }
From source file:org.apache.druid.java.util.common.granularity.DurationGranularity.java
License:Apache License
@Override public boolean isAligned(Interval interval) { if (interval.toDurationMillis() == duration) { return (interval.getStartMillis() - origin) % duration == 0; }//from w w w . j a v a2s .com return false; }
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Measure the duration of an event date in seconds, when a time is * specified, ceiling to the nearest second, when a time is not * specified, from the date midnight at the beginning of a date * range to the last second of the day at the end of the range. This * may return one second less than your expectation for the number * of seconds in the interval (e.g. 86399 seconds for the duration of * a day specified as 1980-01-01.//w w w . j av a 2s . com * * Provides: EVENT_DATE_DURATION_SECONDS * * Suggested by Alex Thompson in a TDWG data quality task group call. * * @param eventDate to test. * @return the duration of eventDate in seconds. */ public static long measureDurationSeconds(String eventDate) { long result = 0l; if (!isEmpty(eventDate)) { Interval eventDateInterval = DateUtils.extractInterval(eventDate); logger.debug(eventDateInterval.toDuration().getStandardDays()); logger.debug(eventDateInterval); long mills = eventDateInterval.toDurationMillis(); result = (long) Math.ceil(mills / 1000l); } return result; }
From source file:org.jbpm.designer.web.server.SimulationServlet.java
License:Apache License
private JSONObject getTimelineEventObject(SimulationEvent se, String intervalUnit, String contextPath) throws Exception { JSONObject seObject = new JSONObject(); seObject.put("id", se.getUUID().toString()); seObject.put("startDate", getDateString(se.getStartTime())); seObject.put("endDate", getDateString(se.getEndTime())); if (se instanceof EndSimulationEvent) { seObject.put("headline", ((EndSimulationEvent) se).getActivityName()); seObject.put("activityid", ((EndSimulationEvent) se).getActivityId()); } else if (se instanceof ActivitySimulationEvent) { seObject.put("headline", ((ActivitySimulationEvent) se).getActivityName()); seObject.put("activityid", ((ActivitySimulationEvent) se).getActivityId()); } else if (se instanceof HumanTaskActivitySimulationEvent) { seObject.put("headline", ((HumanTaskActivitySimulationEvent) se).getActivityName()); seObject.put("activityid", ((HumanTaskActivitySimulationEvent) se).getActivityId()); }/*from www .ja va2s . c o m*/ seObject.put("text", ""); seObject.put("tag", ""); JSONObject seAsset = new JSONObject(); seAsset.put("media", ""); seAsset.put("thumbnail", getIcon(se, contextPath)); seAsset.put("credit", ""); seAsset.put("caption", ""); seObject.put("asset", seAsset); // add aggregated events as well this.eventAggregations.add(se); Interval eventinterval = new Interval(this.simTime.getMillis(), se.getEndTime()); long durationvalue = eventinterval.toDurationMillis(); if (intervalUnit.equals("seconds")) { durationvalue = durationvalue / 1000; } else if (intervalUnit.equals("minutes")) { durationvalue = durationvalue / (1000 * 60); } else if (intervalUnit.equals("hours")) { durationvalue = durationvalue / (1000 * 60 * 60); } else if (intervalUnit.equals("days")) { durationvalue = durationvalue / (1000 * 60 * 60 * 24); } else { // default to milliseconds } this.eventAggregationsTimes.add(durationvalue); return seObject; }
From source file:org.kalypso.ogc.sensor.filter.filters.interval.IntervalValuesOperation.java
License:Open Source License
private IntervalData overlapSourcePart(final Interval targetInterval, final IntervalData sourceData) { final Interval sourceInterval = sourceData.getInterval(); final long sourceDuration = sourceInterval.toDurationMillis(); final Interval sourcePart = targetInterval.overlap(sourceInterval); if (sourcePart == null) return null; final double sourcePartDuration = sourcePart.toDurationMillis(); /*// www .j av a 2 s . c o m * The partial source interval gets only a part of the original value, depending on how much it covers the original * source interval */ final double factor = sourcePartDuration / sourceDuration; // FIXME: performance hot spot... final TupleModelDataSet[] clonedValues = TupleModelDataSet.clone(sourceData.getDataSets()); for (final TupleModelDataSet clone : clonedValues) { clone.setValue(((Number) clone.getValue()).doubleValue() * factor); } return new IntervalData(sourcePart, clonedValues); }
From source file:org.kalypso.ogc.sensor.filter.filters.interval.IntervalValuesOperation.java
License:Open Source License
private IntervalData merge(final IntervalData targetData, final IKeyValue<IntervalData, IntervalData>[] matchingSourceIntervals) { final Interval targetInterval = targetData.getInterval(); final double targetDuration = targetInterval.toDurationMillis(); /* Can this happen? */ // TODO: check i needed if (targetDuration == 0) return targetData; /* No match: return default target */ if (matchingSourceIntervals.length == 0) return targetData; /* Special case: if we have only one exact match, return it to keep the original source */ if (matchingSourceIntervals.length == 1) { final IntervalData sourceData = matchingSourceIntervals[0].getKey(); if (sourceData.getInterval().equals(targetInterval)) return sourceData; }/*from www . j a va2 s .c o m*/ /* Really merge: start with plain data (containing 0.0 values) */ IntervalData mergedData = m_axes.createPlainData(targetInterval); for (final IKeyValue<IntervalData, IntervalData> sourcePair : matchingSourceIntervals) { final IntervalData sourcePart = sourcePair.getValue(); mergedData = mergedData.plus(sourcePart); } return mergedData; }
From source file:org.kuali.coeus.propdev.impl.budget.person.ProposalBudgetProjectPersonnelController.java
License:Open Source License
private void syncLineItemDates(BudgetLineItem budgetLineItem, BudgetPersonnelDetails budgetPersonnelDetails) { long longestDuration = 0; for (BudgetPersonnelDetails detail : budgetLineItem.getBudgetPersonnelDetailsList()) { Interval interval = new Interval(detail.getStartDate().getTime(), detail.getEndDate().getTime()); if (interval.toDurationMillis() >= longestDuration) { longestDuration = interval.toDurationMillis(); budgetLineItem.setStartDate(detail.getStartDate()); budgetLineItem.setEndDate(detail.getEndDate()); }// ww w . ja v a 2 s . c om } }
From source file:org.kuali.hr.lm.leaveCalendar.LeaveCalendarTestUtils.java
License:Educational Community License
/** * From the provided set of parameters, build an action form suitable for * submitting to the TimeDetailAction servlet. In our case, we are mostly * using it in a mock type of situation, the situation of leave block addition. * * @param leaveCalendarDocument/* w w w .j a v a 2s . c o m*/ * @param assignment * @param earnCode * @param start * @param end * @param amount * * @return A populated TimeDetailActionFormBase object. */ public static LeaveCalendarWSForm buildLeaveCalendarForm(LeaveCalendarDocument leaveCalendarDocument, Assignment assignment, EarnCode earnCode, DateTime start, DateTime end, BigDecimal amount, boolean spanningWeeks) { LeaveCalendarWSForm lcf = new LeaveCalendarWSForm(); BigDecimal hours = null; String startTimeS = null; String endTimeS = null; String startDateS; String endDateS; String selectedEarnCode; String selectedAssignment; if (amount == null) { if (start != null && end != null) { Interval se_i = new Interval(start, end); hours = TKUtils.convertMillisToHours(se_i.toDurationMillis()); } // the date/time format is defined in tk.calendar.js. For now, the format is 11/17/2010 8:0 startTimeS = start.toString("H:mm"); endTimeS = end.toString("H:mm"); } else { hours = amount; } startDateS = start.toString("MM/dd/YYYY"); endDateS = end.toString("MM/dd/YYYY"); AssignmentDescriptionKey adk = new AssignmentDescriptionKey(assignment); selectedAssignment = adk.toAssignmentKeyString(); selectedEarnCode = earnCode.getEarnCode(); //lcf.setAcrossDays(acrossDays ? "y" : "n"); lcf.setSpanningWeeks(spanningWeeks ? "y" : "n"); // KPME-1446 lcf.setLeaveAmount(hours); //lcf.setHours(hours); lcf.setStartDate(startDateS); lcf.setEndDate(endDateS); //lcf.setTkTimeBlockId(timeblockId); lcf.setLeaveCalendarDocument(leaveCalendarDocument); lcf.setSelectedAssignment(selectedAssignment); lcf.setSelectedEarnCode(selectedEarnCode); lcf.setMethodToCall("addLeaveBlock"); return lcf; }
From source file:org.kuali.hr.time.util.TimeDetailTestUtils.java
License:Educational Community License
/** * From the provided set of parameters, build an action form suitable for * submitting to the TimeDetailAction servlet. In our case, we are mostly * using it in a mock type of situation. * * @param timeshetDocument// w w w . ja v a2 s . com * @param assignment * @param earnCode * @param start * @param end * @param amount * @param acrossDays * @param timeblockId * * @return A populated TimeDetailActionFormBase object. */ public static TimeDetailActionFormBase buildDetailActionForm(TimesheetDocument timeshetDocument, Assignment assignment, EarnCode earnCode, DateTime start, DateTime end, BigDecimal amount, boolean acrossDays, String timeblockId, boolean spanningWeeks) { TimeDetailActionFormBase tdaf = new TimeDetailActionFormBase(); BigDecimal hours = null; String startTimeS = null; String endTimeS = null; String startDateS; String endDateS; String selectedEarnCode; String selectedAssignment; if (amount == null) { if (start != null && end != null) { Interval se_i = new Interval(start, end); hours = TKUtils.convertMillisToHours(se_i.toDurationMillis()); } // the date/time format is defined in tk.calendar.js. For now, the format is 11/17/2010 8:0 startTimeS = start.toString("H:mm"); endTimeS = end.toString("H:mm"); } startDateS = start.toString("MM/dd/YYYY"); endDateS = end.toString("MM/dd/YYYY"); AssignmentDescriptionKey adk = new AssignmentDescriptionKey(assignment); selectedAssignment = adk.toAssignmentKeyString(); selectedEarnCode = earnCode.getEarnCode(); tdaf.setAcrossDays(acrossDays ? "y" : "n"); tdaf.setSpanningWeeks(spanningWeeks ? "y" : "n"); // KPME-1446 tdaf.setAmount(amount); tdaf.setHours(hours); tdaf.setStartTime(startTimeS); tdaf.setEndTime(endTimeS); tdaf.setStartDate(startDateS); tdaf.setEndDate(endDateS); tdaf.setTkTimeBlockId(timeblockId); tdaf.setTimesheetDocument(timeshetDocument); tdaf.setSelectedAssignment(selectedAssignment); tdaf.setSelectedEarnCode(selectedEarnCode); tdaf.setMethodToCall("addTimeBlock"); return tdaf; }
From source file:org.kuali.kpme.tklm.time.flsa.FlsaDay.java
License:Educational Community License
/** * This method determines if the provided TimeBlock is applicable to this * FLSA day, and if so will add it to the applyList. It could be the case * that a TimeBlock is on the boundary of the FLSA day so that only a * partial amount of the hours for that TimeBlock will count towards this * day./*w w w. j av a 2 s. c o m*/ * * |---------+------------------+---------| * | Day 1 | Day 1/2 Boundary | Day 2 | * |---------+------------------+---------| * | Block 1 | | Block 2 | * |---------+------------------+---------| * * The not so obvious ascii diagram above is intended to illustrate the case * where on day one you have 1 fully overlapping time block (block1) and one * partially overlapping time block (block2). Block 2 belongs to both FLSA * Day 1 and Day 2. * * @param block A time block that we want to check and apply to this day. * @param applyList A list of time blocks we want to add applicable time blocks to. * * @return True if the block is applicable, false otherwise. The return * value can be used as a quick exit for the setTimeBlocks() method. * * TODO : Bucketing of partial FLSA days is still suspect, however real life examples of this are likely non-existent to rare. * * Danger may still lurk in day-boundary overlapping time blocks that have multiple Time Hour Detail entries. */ private boolean applyBlock(TimeBlock block, List<TimeBlock> applyList) { DateTime beginDateTime = block.getBeginDateTime().withZone(timeZone); DateTime endDateTime = block.getEndDateTime().withZone(timeZone); if (beginDateTime.isAfter(flsaDateInterval.getEnd())) return false; Interval timeBlockInterval = null; //Requested to have zero hour time blocks be able to be added to the GUI boolean zeroHoursTimeBlock = false; if (endDateTime.getMillis() > beginDateTime.getMillis()) { timeBlockInterval = new Interval(beginDateTime, endDateTime); } if (flsaDateInterval.contains(beginDateTime)) { zeroHoursTimeBlock = true; } Interval overlapInterval = flsaDateInterval.overlap(timeBlockInterval); long overlap = (overlapInterval == null) ? 0L : overlapInterval.toDurationMillis(); BigDecimal overlapHours = TKUtils.convertMillisToHours(overlap); if ((overlapHours.compareTo(BigDecimal.ZERO) == 0) && flsaDateInterval.contains(beginDateTime) && flsaDateInterval.contains(endDateTime)) { if (block.getHours().compareTo(BigDecimal.ZERO) > 0) { overlapHours = block.getHours(); } } // Local lookup for this time-block to ensure we are not over applicable hours. // You will notice below we are earn codes globally per day, and also locally per timeblock. // The local per-time block mapping is used only to verify that we have not gone over allocated overlap time // for the individual time block. Map<String, BigDecimal> localEarnCodeToHours = new HashMap<String, BigDecimal>(); if (zeroHoursTimeBlock || overlapHours.compareTo(BigDecimal.ZERO) > 0 || (flsaDateInterval.contains(beginDateTime) && StringUtils.equals(block.getEarnCodeType(), HrConstants.EARN_CODE_AMOUNT))) { List<TimeHourDetail> details = block.getTimeHourDetails(); for (TimeHourDetail thd : details) { BigDecimal localEcHours = localEarnCodeToHours.containsKey(thd.getEarnCode()) ? localEarnCodeToHours.get(thd.getEarnCode()) : BigDecimal.ZERO; //NOTE adding this in the last few hours before release.. remove if side effects are noticed if (overlapHours.compareTo(localEcHours) >= 0 || thd.getAmount().compareTo(BigDecimal.ZERO) == 0) { localEcHours = localEcHours.add(thd.getHours(), HrConstants.MATH_CONTEXT); localEarnCodeToHours.put(thd.getEarnCode(), localEcHours); } } List<TimeBlock> blocks = earnCodeToTimeBlocks.get(block.getEarnCode()); if (blocks == null) { blocks = new ArrayList<TimeBlock>(); earnCodeToTimeBlocks.put(block.getEarnCode(), blocks); } blocks.add(block); applyList.add(block); } return true; }