List of usage examples for java.time Instant ofEpochMilli
public static Instant ofEpochMilli(long epochMilli)
From source file:org.briljantframework.data.resolver.Resolve.java
private static Resolver<LocalDate> initializeLocalDateResolver() { Resolver<LocalDate> resolver = new Resolver<>(LocalDate.class); Converter<Long, LocalDate> longToLocalDate = (l) -> Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()) .toLocalDate();/*from w w w . j a va2 s . com*/ resolver.put(String.class, StringToLocalDate.ISO_DATE); resolver.put(Long.class, longToLocalDate); resolver.put(Long.TYPE, longToLocalDate); return resolver; }
From source file:software.reinvent.dependency.parser.service.ArtifactDependencyGraph.java
/** * Adds a model as {@link ArtifactParent}. Parses especially the managed dependencies to make sure that the * dependencies which are child of the parent will contain the versions. * * @param parent the model to add/*from ww w. j a v a 2 s. com*/ */ private void addParent(final Model parent) { final Properties properties = parent.getProperties(); final List<Dependency> managedDependencies = parent.getDependencyManagement().getDependencies(); setVersionToDepencies(parent, managedDependencies); addDependencies(managedDependencies); final ArtifactParent artifactParent = new ArtifactParent(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), LocalDateTime.ofInstant( Instant.ofEpochMilli(parent.getPomFile().lastModified()), ZoneId.systemDefault())); if (artifactParents.contains(artifactParent)) { artifactParents.stream().filter(x -> x.equals(artifactParent)).findFirst().ifPresent(x -> { if (x.getFileDate().isBefore(artifactParent.getFileDate())) { artifactParents.remove(artifactParent); } }); artifactParents.add(artifactParent); } else { artifactParents.add(artifactParent); } }
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 {/* w w w.j av a 2 s .c om*/ // 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; }
From source file:it.tidalwave.northernwind.frontend.ui.component.sitemap.DefaultSitemapViewController.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull/* w w w .j a va2 s . c o m*/ private ZonedDateTime getSiteNodeDateTime(final @Nonnull ResourceProperties properties) { try { final String string = properties.getProperty(Properties.PROPERTY_LATEST_MODIFICATION_DATE); return ZonedDateTime.parse(string, DateTimeFormatter.ISO_DATE_TIME); } catch (NotFoundException e) { } catch (IOException e) { log.warn("", e); } return Instant.ofEpochMilli(0).atZone(ZoneId.of("GMT")); }
From source file:com.google.maps.DistanceMatrixApiTest.java
/** Test duration in traffic with traffic model set. */ @Test//from ww w . ja va 2 s . c om public void testDurationInTrafficWithTrafficModel() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) { final long ONE_HOUR_MILLIS = 60 * 60 * 1000; DistanceMatrixApi.newRequest(sc.context).origins("Fisherman's Wharf, San Francisco") .destinations("San Francisco International Airport, San Francisco, CA").mode(TravelMode.DRIVING) .trafficModel(TrafficModel.PESSIMISTIC) .departureTime(Instant.ofEpochMilli(System.currentTimeMillis() + ONE_HOUR_MILLIS)).await(); sc.assertParamValue("Fisherman's Wharf, San Francisco", "origins"); sc.assertParamValue("San Francisco International Airport, San Francisco, CA", "destinations"); sc.assertParamValue(TravelMode.DRIVING.toUrlValue(), "mode"); sc.assertParamValue(TrafficModel.PESSIMISTIC.toUrlValue(), "traffic_model"); } }
From source file:org.silverpeas.core.web.http.FileResponse.java
/** * Gets expiration date. * @return the expiration date. */ Date getExpirationDate() { return Date.from(Instant.ofEpochMilli(System.currentTimeMillis() + EXPIRE_TIME)); }
From source file:org.openhab.binding.ntp.internal.handler.NtpHandler.java
private synchronized void refreshTimeDate() { if (timeZone != null && locale != null) { long networkTimeInMillis; if (refreshNtpCount <= 0) { networkTimeInMillis = getTime(hostname); timeOffset = networkTimeInMillis - System.currentTimeMillis(); logger.debug("{} delta system time: {}", getThing().getUID(), timeOffset); refreshNtpCount = refreshNtp.intValue(); } else {// ww w .ja v a 2s .c o m networkTimeInMillis = System.currentTimeMillis() + timeOffset; refreshNtpCount--; } ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(networkTimeInMillis), timeZone.toZoneId()); updateState(dateTimeChannelUID, new DateTimeType(zoned)); updateState(stringChannelUID, new StringType(dateTimeFormat.format(zoned))); } else { logger.debug("Not refreshing, since we do not seem to be initialized yet"); } }
From source file:io.stallion.jobs.Schedule.java
/** * Runs the given days of the week, every other week. * * @param startingAt/*from w ww. ja v a2 s . co m*/ * @param days * @return */ public Schedule daysBiweekly(Long startingAt, DayOfWeek... days) { this._days.verifyAndUpdateUnset(); this._days.setIntervalType(Days.IntervalType.BIWEEKLY_DAY_OF_WEEK); for (DayOfWeek day : days) { this._days.add(day.getValue()); } ZonedDateTime startingWeek = ZonedDateTime.ofInstant(Instant.ofEpochMilli(startingAt), ZoneId.of("UTC")); // Get the Monday 12PM of that week startingWeek = startingWeek.minusDays(startingWeek.getDayOfWeek().getValue() - 1).withSecond(0).withHour(12) .withMinute(0).withNano(0); this._days.setStartingDate(startingWeek); return this; }
From source file:org.openhab.binding.wemo.internal.handler.WemoHandler.java
@Override public void onValueReceived(String variable, String value, String service) { logger.debug("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() }); updateStatus(ThingStatus.ONLINE);// ww w . j a va 2 s . c om this.stateMap.put(variable, value); if (getThing().getThingTypeUID().getId().equals("insight")) { String insightParams = stateMap.get("InsightParams"); if (insightParams != null) { String[] splitInsightParams = insightParams.split("\\|"); if (splitInsightParams[0] != null) { OnOffType binaryState = null; binaryState = splitInsightParams[0].equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { logger.trace("New InsightParam binaryState '{}' for device '{}' received", binaryState, getThing().getUID()); updateState(CHANNEL_STATE, binaryState); } } long lastChangedAt = 0; try { lastChangedAt = Long.parseLong(splitInsightParams[1]) * 1000; // convert s to ms } catch (NumberFormatException e) { logger.error("Unable to parse lastChangedAt value '{}' for device '{}'; expected long", splitInsightParams[1], getThing().getUID()); } ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastChangedAt), TimeZone.getDefault().toZoneId()); State lastChangedAtState = new DateTimeType(zoned); if (lastChangedAt != 0) { logger.trace("New InsightParam lastChangedAt '{}' for device '{}' received", lastChangedAtState, getThing().getUID()); updateState(CHANNEL_LASTCHANGEDAT, lastChangedAtState); } State lastOnFor = DecimalType.valueOf(splitInsightParams[2]); if (lastOnFor != null) { logger.trace("New InsightParam lastOnFor '{}' for device '{}' received", lastOnFor, getThing().getUID()); updateState(CHANNEL_LASTONFOR, lastOnFor); } State onToday = DecimalType.valueOf(splitInsightParams[3]); if (onToday != null) { logger.trace("New InsightParam onToday '{}' for device '{}' received", onToday, getThing().getUID()); updateState(CHANNEL_ONTODAY, onToday); } State onTotal = DecimalType.valueOf(splitInsightParams[4]); if (onTotal != null) { logger.trace("New InsightParam onTotal '{}' for device '{}' received", onTotal, getThing().getUID()); updateState(CHANNEL_ONTOTAL, onTotal); } State timespan = DecimalType.valueOf(splitInsightParams[5]); if (timespan != null) { logger.trace("New InsightParam timespan '{}' for device '{}' received", timespan, getThing().getUID()); updateState(CHANNEL_TIMESPAN, timespan); } State averagePower = DecimalType.valueOf(splitInsightParams[6]); // natively given in W if (averagePower != null) { logger.trace("New InsightParam averagePower '{}' for device '{}' received", averagePower, getThing().getUID()); updateState(CHANNEL_AVERAGEPOWER, averagePower); } BigDecimal currentMW = new BigDecimal(splitInsightParams[7]); State currentPower = new DecimalType(currentMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate // mW to W if (currentPower != null) { logger.trace("New InsightParam currentPower '{}' for device '{}' received", currentPower, getThing().getUID()); updateState(CHANNEL_CURRENTPOWER, currentPower); } BigDecimal energyTodayMWMin = new BigDecimal(splitInsightParams[8]); // recalculate mW-mins to Wh State energyToday = new DecimalType( energyTodayMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP)); if (energyToday != null) { logger.trace("New InsightParam energyToday '{}' for device '{}' received", energyToday, getThing().getUID()); updateState(CHANNEL_ENERGYTODAY, energyToday); } BigDecimal energyTotalMWMin = new BigDecimal(splitInsightParams[9]); // recalculate mW-mins to Wh State energyTotal = new DecimalType( energyTotalMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP)); if (energyTotal != null) { logger.trace("New InsightParam energyTotal '{}' for device '{}' received", energyTotal, getThing().getUID()); updateState(CHANNEL_ENERGYTOTAL, energyTotal); } BigDecimal standByLimitMW = new BigDecimal(splitInsightParams[10]); State standByLimit = new DecimalType( standByLimitMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate // mW to W if (standByLimit != null) { logger.trace("New InsightParam standByLimit '{}' for device '{}' received", standByLimit, getThing().getUID()); updateState(CHANNEL_STANDBYLIMIT, standByLimit); } if (currentMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP).intValue() > standByLimitMW .divide(new BigDecimal(1000), RoundingMode.HALF_UP).intValue()) { updateState(CHANNEL_ONSTANDBY, OnOffType.OFF); } else { updateState(CHANNEL_ONSTANDBY, OnOffType.ON); } } } else { State state = stateMap.get("BinaryState").equals("0") ? OnOffType.OFF : OnOffType.ON; logger.debug("State '{}' for device '{}' received", state, getThing().getUID()); if (state != null) { if (getThing().getThingTypeUID().getId().equals("motion")) { updateState(CHANNEL_MOTIONDETECTION, state); if (state.equals(OnOffType.ON)) { State lastMotionDetected = new DateTimeType(); updateState(CHANNEL_LASTMOTIONDETECTED, lastMotionDetected); } } else { updateState(CHANNEL_STATE, state); } } } }
From source file:com.amazonaws.services.kinesis.io.ObjectExtractor.java
/** * {@inheritDoc}/*from ww w .ja v a 2s. com*/ */ @Override public List<AggregateData> getData(InputEvent event) throws SerializationException { if (!validated) { try { validate(); } catch (Exception e) { throw new SerializationException(e); } } try { List<AggregateData> data = new ArrayList<>(); Object o = serialiser.toClass(event); // get the value of the reflected labels LabelSet labels = new LabelSet(); for (String key : this.aggregateLabelMethods) { labels.put(key, aggregateLabelMethodMap.get(key).invoke(o).toString()); } // get the unique ID value from the object String uniqueId = null; if (this.uniqueIdMethodName != null) { switch (this.uniqueIdMethodName) { case StreamAggregator.REF_PARTITION_KEY: uniqueId = event.getPartitionKey(); break; case StreamAggregator.REF_SEQUENCE: uniqueId = event.getSequenceNumber(); break; default: Object id = uniqueIdMethod.invoke(o); if (id != null) { uniqueId = id.toString(); } break; } } // get the date value from the object if (this.dateMethod != null) { eventDate = dateMethod.invoke(o); if (eventDate == null) { dateValue = OffsetDateTime.now(ZoneId.of("UTC")); } else { if (eventDate instanceof Date) { dateValue = OffsetDateTime.ofInstant(((Date) eventDate).toInstant(), ZoneId.of("UTC")); } else if (eventDate instanceof Long) { dateValue = OffsetDateTime.ofInstant(Instant.ofEpochMilli((Long) eventDate), ZoneId.of("UTC")); } else { throw new Exception(String.format("Cannot use data type %s for date value on event", eventDate.getClass().getSimpleName())); } } } // extract all summed values from the serialised object if (this.aggregatorType.equals(AggregatorType.SUM)) { // lift out the aggregated method value for (String s : this.sumValueMap.keySet()) { summaryValue = this.sumValueMap.get(s).invoke(o); if (summaryValue != null) { if (summaryValue instanceof Double) { sumUpdates.put(s, (Double) summaryValue); } else if (summaryValue instanceof Long) { sumUpdates.put(s, ((Long) summaryValue).doubleValue()); } else if (summaryValue instanceof Integer) { sumUpdates.put(s, ((Integer) summaryValue).doubleValue()); } else { String msg = String.format("Unable to access Summary %s due to NumberFormatException", s); LOG.error(msg); throw new SerializationException(msg); } } } } data.add(new AggregateData(uniqueId, labels, dateValue, sumUpdates)); return data; } catch (Exception e) { throw new SerializationException(e); } }