List of usage examples for java.time ZonedDateTime minus
@Override
public ZonedDateTime minus(TemporalAmount amountToSubtract)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.minus(Period.ofDays(12)); System.out.println(n);/*from w w w. j a v a2 s .com*/ }
From source file:dk.dma.vessel.track.store.AisStoreClient.java
public List<PastTrackPos> getPastTrack(int mmsi, Integer minDist, Duration age) { // Determine URL age = age != null ? age : Duration.parse(pastTrackTtl); minDist = minDist == null ? Integer.valueOf(pastTrackMinDist) : minDist; ZonedDateTime now = ZonedDateTime.now(); String from = now.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime end = now.minus(age); String to = end.format(DateTimeFormatter.ISO_INSTANT); String interval = String.format("%s/%s", to, from); String url = String.format("%s?mmsi=%d&interval=%s", aisViewUrl, mmsi, interval); final List<PastTrackPos> track = new ArrayList<>(); try {/*from w ww .ja v a 2s . co m*/ long t0 = System.currentTimeMillis(); // TEST url = url + "&filter=" + URLEncoder.encode("(s.country not in (GBR)) & (s.region!=808)", "UTF-8"); // Set up a few timeouts and fetch the attachment URLConnection con = new URL(url).openConnection(); con.setConnectTimeout(10 * 1000); // 10 seconds con.setReadTimeout(60 * 1000); // 1 minute if (!StringUtils.isEmpty(aisAuthHeader)) { con.setRequestProperty("Authorization", aisAuthHeader); } try (InputStream in = con.getInputStream(); BufferedInputStream bin = new BufferedInputStream(in)) { AisReader aisReader = AisReaders.createReaderFromInputStream(bin); aisReader.registerPacketHandler(new Consumer<AisPacket>() { @Override public void accept(AisPacket p) { AisMessage message = p.tryGetAisMessage(); if (message == null || !(message instanceof IVesselPositionMessage)) { return; } VesselTarget target = new VesselTarget(); target.merge(p, message); if (!target.checkValidPos()) { return; } track.add(new PastTrackPos(target.getLat(), target.getLon(), target.getCog(), target.getSog(), target.getLastPosReport())); } }); aisReader.start(); try { aisReader.join(); } catch (InterruptedException e) { return null; } } LOG.info(String.format("Read %d past track positions in %d ms", track.size(), System.currentTimeMillis() - t0)); } catch (IOException e) { LOG.error("Failed to make REST query: " + url); throw new InternalError("REST endpoint failed"); } LOG.info("AisStore returned track with " + track.size() + " points"); return PastTrack.downSample(track, minDist, age.toMillis()); }
From source file:nu.yona.server.analysis.service.AnalysisEngineService.java
private ZonedDateTime correctTime(Duration deviceTimeOffset, ZonedDateTime time) { return time.minus(deviceTimeOffset); }
From source file:bamboo.trove.rule.RuleChangeUpdateManager.java
@VisibleForTesting public SolrQuery convertRuleToSearch(CdxRule rule, String notLastIndexed) { // URL complexity first List<String> urlQueries = new ArrayList<>(); for (String url : rule.getUrlPatterns()) { if (!url.trim().isEmpty()) { urlQueries.add(urlSearch(url)); }/*from w w w . j av a 2 s. c o m*/ } if (urlQueries.isEmpty()) { urlQueries.add("*:*"); } SolrQuery query = createQuery("(" + StringUtils.join(urlQueries, ") OR (") + ")"); // Filter out stuff we have touched already this run query.addFilterQuery(notLastIndexed); // Filter for Embargo if (rule.getPeriod() != null && !rule.getPeriod().isZero()) { // TODAY +/- embargo period ZonedDateTime today = ZonedDateTime.ofInstant(CdxRestrictionService.TODAY.toInstant(), TZ); Date embargoStart = Date.from(today.minus(rule.getPeriod()).toInstant()); query.addFilterQuery(SolrEnum.DATE + ":[" + format.format(embargoStart) + " TO *]"); } // Filter for Capture date if (rule.getCaptured() != null && rule.getCaptured().hasData()) { query.addFilterQuery(SolrEnum.DATE + ":[" + format.format(rule.getCaptured().start) + " TO " + format.format(rule.getCaptured().end) + "]"); } // Worth noting we don't filter for access date because it is one of the // deciding data points in whether or not to run this query at all. return query; }
From source file:org.openhab.binding.airvisualnode.internal.handler.AirVisualNodeHandler.java
private State getChannelState(String channelId, NodeData nodeData) { State state = UnDefType.UNDEF; // Handle system channel IDs separately, because 'switch/case' expressions must be constant expressions if (CHANNEL_BATTERY_LEVEL.equals(channelId)) { state = new DecimalType(BigDecimal.valueOf(nodeData.getStatus().getBattery()).longValue()); } else if (CHANNEL_WIFI_STRENGTH.equals(channelId)) { state = new DecimalType( BigDecimal.valueOf(Math.max(0, nodeData.getStatus().getWifiStrength() - 1)).longValue()); } else {/*from w ww .ja va 2s . com*/ // Handle binding-specific channel IDs switch (channelId) { case CHANNEL_CO2: state = new QuantityType<>(nodeData.getMeasurements().getCo2Ppm(), PARTS_PER_MILLION); break; case CHANNEL_HUMIDITY: state = new QuantityType<>(nodeData.getMeasurements().getHumidityRH(), PERCENT); break; case CHANNEL_AQI_US: state = new QuantityType<>(nodeData.getMeasurements().getPm25AQIUS(), ONE); break; case CHANNEL_PM_25: // PM2.5 is in ug/m3 state = new QuantityType<>(nodeData.getMeasurements().getPm25Ugm3(), MICRO(GRAM).divide(CUBIC_METRE)); break; case CHANNEL_TEMP_CELSIUS: state = new QuantityType<>(nodeData.getMeasurements().getTemperatureC(), CELSIUS); break; case CHANNEL_TIMESTAMP: // It seem the Node timestamp is Unix timestamp converted from UTC time plus timezone offset. // Not sure about DST though, but it's best guess at now Instant instant = Instant.ofEpochMilli(nodeData.getStatus().getDatetime() * 1000L); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")); ZoneId zoneId = ZoneId.of(nodeData.getSettings().getTimezone()); ZoneRules zoneRules = zoneId.getRules(); zonedDateTime.minus(Duration.ofSeconds(zoneRules.getOffset(instant).getTotalSeconds())); if (zoneRules.isDaylightSavings(instant)) { zonedDateTime.minus(Duration.ofSeconds(zoneRules.getDaylightSavings(instant).getSeconds())); } state = new DateTimeType(zonedDateTime); break; case CHANNEL_USED_MEMORY: state = new DecimalType(BigDecimal.valueOf(nodeData.getStatus().getUsedMemory()).longValue()); break; } } return state; }