List of usage examples for org.joda.time DateTime minus
public DateTime minus(ReadablePeriod period)
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsFilterDelegate.java
License:Open Source License
@Override public FilterType relative(String propertyName, long duration) { DateTime now = new DateTime(); DateTime startDate = now.minus(duration); return buildDuringFilterType(mapMetacardAttribute(propertyName), convertDateToIso8601Format(startDate), convertDateToIso8601Format(now)); }
From source file:org.emonocot.api.job.JobExecutionInfo.java
License:Open Source License
public JobExecutionInfo(JobExecution jobExecution, String baseUrl) { resourceIdentifier = jobExecution.getJobInstance().getJobParameters().getString("resource.identifier"); DateTime sTime = new DateTime(jobExecution.getStartTime()); DateTime eTime = new DateTime(jobExecution.getEndTime()); duration = eTime.minus(sTime.getMillis()); startTime = sTime;/*from w w w. jav a 2s .c om*/ exitDescription = jobExecution.getExitStatus().getExitDescription(); exitCode = jobExecution.getExitStatus().getExitCode(); id = jobExecution.getId(); jobInstance = baseUrl + "/jobs/" + jobExecution.getJobInstance().getJobName() + "/" + jobExecution.getJobInstance().getId(); resource = baseUrl + "/jobs/executions/" + jobExecution.getId(); this.baseUrl = baseUrl; status = jobExecution.getStatus(); Integer writeSkip = 0; for (StepExecution stepExecution : jobExecution.getStepExecutions()) { recordsRead += stepExecution.getReadCount(); readSkip += stepExecution.getReadSkipCount(); processSkip += stepExecution.getProcessSkipCount(); written += stepExecution.getWriteCount(); writeSkip += stepExecution.getWriteSkipCount(); } }
From source file:org.fao.geonet.domain.ISODate.java
License:Open Source License
public static String parseISODateTimes(String input1, String input2) { DateTimeFormatter dto = ISODateTimeFormat.dateTime(); PeriodFormatter p = ISOPeriodFormat.standard(); DateTime odt1; String odt = ""; // input1 should be some sort of ISO time // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc // convert everything to UTC so that we remove any timezone // problems//from w w w .j a v a 2 s . c o m try { DateTime idt = parseBasicOrFullDateTime(input1); odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt1.toString(); } catch (Exception e) { Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e); return DEFAULT_DATE_TIME; } if (input2 == null || input2.equals("")) return odt; // input2 can be an ISO time as for input1 but also an ISO time period // eg. -P3D or P3D - if an ISO time period then it must be added to the // DateTime generated for input1 (odt1) // convert everything to UTC so that we remove any timezone // problems try { boolean minus = false; if (input2.startsWith("-P")) { input2 = input2.substring(1); minus = true; } if (input2.startsWith("P")) { Period ip = p.parsePeriod(input2); DateTime odt2; if (!minus) odt2 = odt1.plus(ip.toStandardDuration().getMillis()); else odt2 = odt1.minus(ip.toStandardDuration().getMillis()); odt = odt + "|" + odt2.toString(); } else { DateTime idt = parseBasicOrFullDateTime(input2); DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt + "|" + odt2.toString(); } } catch (Exception e) { Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e); return odt + "|" + DEFAULT_DATE_TIME; } return odt; }
From source file:org.fao.geonet.util.JODAISODate.java
License:Open Source License
public static String parseISODateTimes(String input1, String input2) { DateTimeFormatter dto = ISODateTimeFormat.dateTime(); PeriodFormatter p = ISOPeriodFormat.standard(); DateTime odt1; String odt = ""; // input1 should be some sort of ISO time // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc // convert everything to UTC so that we remove any timezone // problems//www . java 2 s.c om try { DateTime idt = parseBasicOrFullDateTime(input1); odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt1.toString(); } catch (Exception e) { e.printStackTrace(); return dt; } if (input2 == null || input2.equals("")) return odt; // input2 can be an ISO time as for input1 but also an ISO time period // eg. -P3D or P3D - if an ISO time period then it must be added to the // DateTime generated for input1 (odt1) // convert everything to UTC so that we remove any timezone // problems try { boolean minus = false; if (input2.startsWith("-P")) { input2 = input2.substring(1); minus = true; } if (input2.startsWith("P")) { Period ip = p.parsePeriod(input2); DateTime odt2; if (!minus) odt2 = odt1.plus(ip.toStandardDuration().getMillis()); else odt2 = odt1.minus(ip.toStandardDuration().getMillis()); odt = odt + "|" + odt2.toString(); } else { DateTime idt = parseBasicOrFullDateTime(input2); DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt + "|" + odt2.toString(); } } catch (Exception e) { e.printStackTrace(); return odt + "|" + dt; } return odt; }
From source file:org.forgerock.openidm.util.ConfigMacroUtil.java
License:Open Source License
/** * Handles the Time.now macro/*from w ww . j a v a 2s . co m*/ * * @param tokens * list of tokens * @param iter * iterator used to iterate over the list of tokens * @return string containing the interpolated time token */ private static String handleTime(List<String> tokens, Iterator<String> iter) { DateTime dt = new DateTime(); // Add some amount if (iter.hasNext()) { String operationToken = iter.next(); if (operationToken.equals("+") || operationToken.equals("-")) { if (iter.hasNext()) { String quantityToken = iter.next(); // Get the magnitude to // add or subtract ReadablePeriod period = getTimePeriod(quantityToken); if (operationToken.equals("-")) { dt = dt.minus(period); } else { dt = dt.plus(period); } } else { logger.warn("Token '{}' not followed by a quantity", operationToken); } } else { logger.warn("Invalid token '{}', must be operator '+' or '-'", operationToken); } } return DATE_UTIL.formatDateTime(dt); }
From source file:org.graylog.plugins.netflow.flows.NetFlowV5.java
License:Apache License
/** * Parse a Version 5 Flow/*from w ww . j av a2 s . com*/ * * @param sender The sender's InetSocketAddress * @param buf Netty ByteBuf Slice containing the UDP Packet * @param fpId FlowPacket-UUID this Flow arrived on * @param uptime Millis since UNIX Epoch when the exporting device/sender booted * @param timestamp DateTime when this flow was exported * @param samplingInterval Interval samples are sent * @param calculateSamples Switch to turn on/off samples calculation */ public static NetFlow parse(final InetSocketAddress sender, final ByteBuf buf, final UUID fpId, final long uptime, final DateTime timestamp, final int samplingInterval, final boolean calculateSamples) { final long pkts = getUnsignedInteger(buf, 16, 4); final long bytes = getUnsignedInteger(buf, 20, 4); final int srcPort = (int) getUnsignedInteger(buf, 32, 2); final int dstPort = (int) getUnsignedInteger(buf, 34, 2); final int srcAS = (int) getUnsignedInteger(buf, 40, 2); final int dstAS = (int) getUnsignedInteger(buf, 42, 2); final int proto = buf.getUnsignedByte(38); final int tos = buf.getUnsignedByte(39); final int tcpflags = buf.getUnsignedByte(37); final long start = getUnsignedInteger(buf, 24, 4); final long stop = getUnsignedInteger(buf, 28, 4); final InetAddress srcAddress = getInetAddress(buf, 0, 4); final InetAddress dstAddress = getInetAddress(buf, 4, 4); final InetAddress nextHop = getInetAddress(buf, 8, 4); final int snmpInput = (int) getUnsignedInteger(buf, 12, 2); final int snmpOutput = (int) getUnsignedInteger(buf, 14, 2); final int srcMask = buf.getUnsignedByte(44); final int dstMask = buf.getUnsignedByte(45); return new NetFlowV5(UUIDs.timeBased(), sender, buf.readableBytes(), uptime, timestamp, srcPort, dstPort, srcAS != -1 ? Optional.of(srcAS) : Optional.<Integer>absent(), dstAS != -1 ? Optional.of(dstAS) : Optional.<Integer>absent(), calculateSamples ? pkts * samplingInterval : pkts, // pkts calculateSamples ? bytes * samplingInterval : bytes, // bytes proto, tos, tcpflags, start != 0 ? Optional.of(timestamp.minus(uptime - start)) : Optional.<DateTime>absent(), // start stop != 0 ? Optional.of(timestamp.minus(uptime - stop)) : Optional.<DateTime>absent(), // stop srcAddress, dstAddress, ByteBufUtils.DEFAULT_INET_ADDRESS.equals(nextHop) ? Optional.<InetAddress>absent() : Optional.of(nextHop), // nextHop snmpInput, snmpOutput, srcMask, dstMask, fpId); }
From source file:org.graylog.plugins.pipelineprocessor.ast.expressions.AdditionExpression.java
License:Open Source License
@Nullable @Override/*from w w w . j a v a2 s . co m*/ public Object evaluateUnsafe(EvaluationContext context) { final Object leftValue = left.evaluateUnsafe(context); final Object rightValue = right.evaluateUnsafe(context); // special case for date arithmetic final boolean leftDate = DateTime.class.equals(leftValue.getClass()); final boolean leftPeriod = Period.class.equals(leftValue.getClass()); final boolean rightDate = DateTime.class.equals(rightValue.getClass()); final boolean rightPeriod = Period.class.equals(rightValue.getClass()); if (leftDate && rightPeriod) { final DateTime date = (DateTime) leftValue; final Period period = (Period) rightValue; return isPlus() ? date.plus(period) : date.minus(period); } else if (leftPeriod && rightDate) { final DateTime date = (DateTime) rightValue; final Period period = (Period) leftValue; return isPlus() ? date.plus(period) : date.minus(period); } else if (leftPeriod && rightPeriod) { final Period period1 = (Period) leftValue; final Period period2 = (Period) rightValue; return isPlus() ? period1.plus(period2) : period1.minus(period2); } else if (leftDate && rightDate) { // the most uncommon, this is only defined for - really and means "interval between them" // because adding two dates makes no sense if (isPlus()) { // makes no sense to compute and should be handles in the parser already return null; } final DateTime left = (DateTime) leftValue; final DateTime right = (DateTime) rightValue; if (left.isBefore(right)) { return new Duration(left, right); } else { return new Duration(right, left); } } if (isIntegral()) { final long l = (long) leftValue; final long r = (long) rightValue; if (isPlus) { return l + r; } else { return l - r; } } else { final double l = (double) leftValue; final double r = (double) rightValue; if (isPlus) { return l + r; } else { return l - r; } } }
From source file:org.graylog2.dashboards.widgets.SearchResultCountWidget.java
License:Open Source License
protected ComputationResult computeInternal(String filter) { CountResult cr = searches.count(query, timeRange, filter); if (trend && timeRange instanceof RelativeRange) { DateTime toPrevious = timeRange.getFrom(); DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange())); TimeRange previousTimeRange = new AbsoluteRange(fromPrevious, toPrevious); CountResult previousCr = searches.count(query, previousTimeRange); Map<String, Object> results = Maps.newHashMap(); results.put("now", cr.getCount()); results.put("previous", previousCr.getCount()); long tookMs = cr.getTookMs() + previousCr.getTookMs(); return new ComputationResult(results, tookMs); } else {//from w w w.j a v a2 s. co m return new ComputationResult(cr.getCount(), cr.getTookMs()); } }
From source file:org.graylog2.dashboards.widgets.StatisticalCountWidget.java
License:Open Source License
@Override protected ComputationResult compute() { try {/* w w w . j a v a2 s . c o m*/ final String filter; if (!isNullOrEmpty(streamId)) { filter = "streams:" + streamId; } else { filter = null; } FieldStatsResult fieldStatsResult = getSearches().fieldStats(field, query, filter, timeRange); if (trend && timeRange instanceof RelativeRange) { DateTime toPrevious = timeRange.getFrom(); DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange())); TimeRange previousTimeRange = new AbsoluteRange(fromPrevious, toPrevious); FieldStatsResult previousFieldStatsResult = getSearches().fieldStats(field, query, filter, previousTimeRange); Map<String, Object> results = Maps.newHashMap(); results.put("now", getStatisticalValue(fieldStatsResult)); results.put("previous", getStatisticalValue(previousFieldStatsResult)); long tookMs = fieldStatsResult.took().millis() + previousFieldStatsResult.took().millis(); return new ComputationResult(results, tookMs); } else { return new ComputationResult(getStatisticalValue(fieldStatsResult), fieldStatsResult.took().millis()); } } catch (Searches.FieldTypeException e) { throw new RuntimeException("Invalid field provided.", e); } }
From source file:org.graylog2.dashboards.widgets.strategies.SearchResultCountWidgetStrategy.java
License:Open Source License
protected ComputationResult computeInternal(String filter) { final TimeRange timeRange = this.timeRange; CountResult cr = searches.count(query, timeRange, filter); if (trend && timeRange instanceof RelativeRange) { DateTime toPrevious = timeRange.getFrom(); DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange())); TimeRange previousTimeRange = AbsoluteRange.create(fromPrevious, toPrevious); CountResult previousCr = searches.count(query, previousTimeRange); Map<String, Object> results = Maps.newHashMap(); results.put("now", cr.count()); results.put("previous", previousCr.count()); long tookMs = cr.tookMs() + previousCr.tookMs(); return new ComputationResult(results, tookMs); } else {//from w w w . j av a 2 s . c o m return new ComputationResult(cr.count(), cr.tookMs()); } }