List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:eu.itesla_project.merge.MergeUtil.java
License:Mozilla Public License
public static int getDateDistanceToReference(VoltageLevel vl) { DateTime caseDate;//from ww w . j av a 2 s . c o m String caseDateStr = vl.getProperties().getProperty(CASE_DATE); if (caseDateStr == null) { caseDate = vl.getSubstation().getNetwork().getCaseDate(); } else { caseDate = DateTime.parse(caseDateStr); } return (int) new Duration(caseDate, vl.getSubstation().getNetwork().getCaseDate()).getStandardMinutes(); }
From source file:eu.itesla_project.offline.monitoring.BusyCoresSeries.java
License:Mozilla Public License
private void clean() { // clean old data DateTime now = DateTime.now();/* ww w.j ava 2 s . c o m*/ for (Iterator<Value> it = values.iterator(); it.hasNext();) { Value value = it.next(); if (new Duration(value.getDate(), now).getStandardMinutes() > 1) { it.remove(); } } }
From source file:eu.itesla_project.offline.tools.ListOfflineWorkflowsTool.java
License:Mozilla Public License
@Override public void run(CommandLine line) throws Exception { try (OfflineApplication app = new RemoteOfflineApplicationImpl()) { Map<String, OfflineWorkflowStatus> statuses = app.listWorkflows(); Table table = new Table(4, BorderStyle.CLASSIC_WIDE); table.addCell("ID"); table.addCell("Running"); table.addCell("Step"); table.addCell("Time"); for (Map.Entry<String, OfflineWorkflowStatus> entry : statuses.entrySet()) { String workflowId = entry.getKey(); OfflineWorkflowStatus status = entry.getValue(); Duration remaining = null; if (status.getStartTime() != null) { remaining = Duration.millis(status.getStartParameters().getDuration() * 60 * 1000) .minus(new Duration(status.getStartTime(), DateTime.now())); }// w ww .j a v a 2s . c o m table.addCell(workflowId); table.addCell(Boolean.toString(status.isRunning())); table.addCell(status.getStep() != null ? status.getStep().toString() : ""); table.addCell(remaining != null ? PeriodFormat.getDefault().print(remaining.toPeriod()) : ""); } System.out.println(table.render()); } }
From source file:fi.hsl.parkandride.back.prediction.PredictionDao.java
License:EUPL
private List<Prediction> filterToSelectedPredictionDistances(DateTime start, List<Prediction> predictions) { return predictions.stream() .filter(p -> predictionsDistancesToStore.contains(new Duration(start, p.timestamp))) .collect(toList());/* w w w .j av a2 s . com*/ }
From source file:fi.hsl.parkandride.back.prediction.PredictionDao.java
License:EUPL
private static BinaryOperator<List<Prediction>> linearInterpolation() { return (interpolated, input) -> { if (input.size() != 1) { throw new IllegalArgumentException("expected one element, but got " + input); }//from ww w. j a va 2 s .c om if (interpolated.isEmpty()) { interpolated.addAll(input); return interpolated; } Prediction previous = interpolated.get(interpolated.size() - 1); Prediction next = input.get(0); for (DateTime timestamp = previous.timestamp.plus(PREDICTION_RESOLUTION); timestamp .isBefore(next.timestamp); timestamp = timestamp.plus(PREDICTION_RESOLUTION)) { double totalDuration = new Duration(previous.timestamp, next.timestamp).getMillis(); double currentDuration = new Duration(previous.timestamp, timestamp).getMillis(); double proportion = currentDuration / totalDuration; int totalChange = next.spacesAvailable - previous.spacesAvailable; int currentChange = (int) Math.round(totalChange * proportion); int spacesAvailable = previous.spacesAvailable + currentChange; interpolated.add(new Prediction(timestamp, spacesAvailable)); } interpolated.add(next); return interpolated; }; }
From source file:fi.hsl.parkandride.back.prediction.PredictionDao.java
License:EUPL
private void savePredictionHistory(Long predictorId, DateTime start, List<Prediction> predictions) { if (!predictions.isEmpty()) { final SQLInsertClause insert = queryFactory.insert(qPredictionHistory); predictions.forEach(p -> insert.set(qPredictionHistory.predictorId, predictorId) .set(qPredictionHistory.forecastDistanceInMinutes, ((int) new Duration(start, p.timestamp).getStandardMinutes())) .set(qPredictionHistory.ts, p.timestamp) .set(qPredictionHistory.spacesAvailable, p.spacesAvailable).addBatch()); insert.execute();/*from w w w. j av a 2s . c o m*/ } }
From source file:fr.amap.commons.animation.Timeline.java
/** * //from www . j a va 2s . co m * @param startTime * @param endTime * @param timeStep Time step in decimal hour. */ public Timeline(DateTime startTime, DateTime endTime, double timeStep) { this.startTime = startTime; this.endTime = endTime; this.timeStep = timeStep; periodDuration = new Duration(startTime, endTime); double hours = periodDuration.getStandardSeconds() / 3600.0; nbSteps = (int) (hours / timeStep) + 1; keyFrames = new KeyFrame[nbSteps]; events = new ArrayList[nbSteps]; }
From source file:fr.amap.commons.animation.Timeline.java
/** * Get the nearest index in the timeline from the DateTime. * @param timePosition//from w w w. j a v a 2s . com * @return */ private int getNearestIndex(DateTime timePosition) { //get array index from timePosition Duration durationFromStart = new Duration(startTime, timePosition); long millisDuration = durationFromStart.getMillis(); int index = (int) Math.round((millisDuration / 1000.0 / 3600.0) / timeStep); if (index >= nbSteps) { index = nbSteps - 1; } else if (index < 0/* || index >= nbSteps*/) { index = 0; } return index; }
From source file:gobblin.data.management.retention.policy.TimeBasedRetentionPolicy.java
License:Apache License
/** * Since months and years can have arbitrary days, joda time does not allow conversion of a period string containing * months or years to a duration. Hence we calculate the duration using 1970 01:01:00:00:00 UTC as a reference time. * * <p>/*from www . ja va 2 s.co m*/ * <code> * (1970 01:01:00:00:00 + P2Y) - 1970 01:01:00:00:00 = Duration for 2 years * </code> * </p> * * @param periodString * @return duration for this period. */ private static Duration parseDuration(String periodString) { DateTime zeroEpoc = new DateTime(0); return new Duration(zeroEpoc, zeroEpoc.plus(ISOPeriodFormat.standard().parsePeriod(periodString))); }
From source file:google.registry.export.DatastoreBackupInfo.java
License:Open Source License
/** * Returns the length of time the backup ran for (if completed) or the length of time since the * backup started (if it has not completed). *//*from ww w.j a v a 2s . co m*/ public Duration getRunningTime() { return new Duration(startTime, completeTime.or(clock.nowUtc())); }