List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
/** * /*from w ww . ja va 2s. c o m*/ * @param path int of the path to get the Time Options for * @param storedTimePref Long of anytime during the specific day that we want to return times for * @return populates the "times" TreeSet (time longs truncated at the "the seconds" position) * which populates Time Combo box, the truncTimeToFullTimeMap which maps the truncated times * im times TreeSet to each times full Long value. The truncTimeToFullTimeMap chooses each time * up to the second and maps it to the greatest equivalent time up to the milliseconds. * */ protected void setTimeOptions(int path, Long storedTimePref) { try { timeSelectCombo.getItems().clear(); overrideTimestamp = null; Date startDate = null, finishDate = null; if (storedTimePref != null) { StampBdb stampDb = Bdb.getStampDb(); NidSet nidSet = new NidSet(); nidSet.add(path); NidSetBI stamps = null; if (!storedTimePref.equals(getDefaultTime())) { startDate = getStartOfDay(new Date(storedTimePref)); finishDate = getEndOfDay(new Date(storedTimePref)); stamps = stampDb.getSpecifiedStamps(nidSet, startDate.getTime(), finishDate.getTime()); } else { stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); } truncTimeToFullTimeMap.clear(); times.clear(); HashSet<Integer> stampSet = stamps.getAsSet(); Date d = new Date(storedTimePref); if (dateIsLocalDate(d)) { // Get stamps of day Date todayStartDate = getStartOfDay(new Date()); Date todayFinishDate = getEndOfDay(new Date()); NidSetBI todayStamps = stampDb.getSpecifiedStamps(nidSet, todayStartDate.getTime(), todayFinishDate.getTime()); // If have stamps, no action, if not, show Latest and set stamps to latest stamp we have in stampset if (todayStamps.size() == 0) { // timeSelectCombo.getItems().add(Long.MAX_VALUE); NidSetBI allStamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); HashSet<Integer> allStampSet = allStamps.getAsSet(); SortedSet<Integer> s = new TreeSet<Integer>(allStampSet); if (!s.isEmpty()) { Integer stampToSet = s.last(); overrideTimestamp = stampDb.getPosition(stampToSet).getTime(); timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); } } } this.pathDatesList.add(LocalDate.now()); if (overrideTimestamp == null) { if (!stampSet.isEmpty()) { enableTimeCombo(true); for (Integer thisStamp : stampSet) { Long fullTime = null; Date stampDate; LocalDate stampInstant = null; try { fullTime = stampDb.getPosition(thisStamp).getTime(); stampDate = new Date(fullTime); stampInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(new Date(fullTime)); cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds Long truncTime = cal.getTimeInMillis(); this.pathDatesList.add(stampInstant); //Build DatePicker times.add(truncTime); //This can probably go, we don't populate hashmap like this at initialization timeSelectCombo.getItems().add(truncTime); if (truncTimeToFullTimeMap.containsKey(truncTime)) { //Build Truncated Time to Full Time HashMap //If truncTimeToFullTimeMap has this key, is the value the newest time in milliseconds? if (new Date(truncTimeToFullTimeMap.get(truncTime)).before(new Date(fullTime))) { truncTimeToFullTimeMap.put(truncTime, fullTime); } } else { truncTimeToFullTimeMap.put(truncTime, fullTime); } } } else { // disableTimeCombo(true); // timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); enableTimeCombo(true); // logger.error("Could not retreive any Stamps"); } } } } catch (Exception e) { logger.error("Error setting the default Time Dropdown"); e.printStackTrace(); } }
From source file:org.silverpeas.core.calendar.notification.CalendarContributionReminderUserNotificationTest.java
private void triggerDateTime(DurationReminder reminder) throws IllegalAccessException { Optional<Contribution> contribution = contributionManager.getById(reminder.getContributionId()); if (contribution.isPresent()) { final CalendarEvent event = (CalendarEvent) contribution.get(); final OffsetDateTime occStartDate; if (event.isOnAllDay()) { occStartDate = ((LocalDate) currentPeriod.getStartDate()) .atStartOfDay(event.getCalendar().getZoneId()).toOffsetDateTime(); } else {//from www . j av a 2 s .com occStartDate = (OffsetDateTime) currentPeriod.getStartDate(); } final OffsetDateTime finalDateTime = occStartDate .minus(reminder.getDuration(), reminder.getTimeUnit().toChronoUnit()).toZonedDateTime() .withZoneSameInstant(ZoneId.systemDefault()).toOffsetDateTime(); FieldUtils.writeField(reminder, "triggerDateTime", finalDateTime, true); } }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java
List<Date> getUserAssignmentPartitions(Date fromTime, Date toTime) { final LocalDateTime startTime = LocalDateTime.ofInstant(fromTime.toInstant(), ZoneId.systemDefault()) .withMinute(0).withSecond(0).withNano(0); final LocalDateTime endTime = LocalDateTime.ofInstant(toTime.toInstant(), ZoneId.systemDefault()) .withMinute(0).withSecond(0).withNano(0); final long hours = Duration.between(startTime, endTime).toHours(); return LongStream.rangeClosed(0, hours).mapToObj(startTime::plusHours) .map(t -> Date.from(t.atZone(ZoneId.systemDefault()).toInstant())).collect(Collectors.toList()); }
From source file:net.di2e.ecdr.describe.generator.DescribeGeneratorImpl.java
protected void setRecordRate(MetricsType metrics, Map<String, TemporalCoverageHolder> timeMap) { TemporalCoverageHolder tc = timeMap.containsKey("modified") ? (TemporalCoverageHolder) timeMap.get("modified") : (timeMap.containsKey("effective") ? (TemporalCoverageHolder) timeMap.get("effective") : (TemporalCoverageHolder) timeMap.get("created")); try {//from ww w.java2 s.c o m if (tc != null) { Date startDate = tc.getStartDate(); if (startDate != null) { long totalHits = metrics.getCount(); LocalDateTime start = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault()); Duration duration = Duration.between(start, LocalDateTime.now()); RecordRateType rate = new RecordRateType(); metrics.setRecordRate(rate); long dur = totalHits / duration.toHours(); if (dur < 15L) { dur = totalHits / duration.toDays(); if (dur < 4L) { dur = totalHits * 30L / duration.toDays(); if (dur < 10L) { dur = totalHits * 365L / duration.toDays(); rate.setFrequency("Yearly"); } else { rate.setFrequency("Monthly"); } } else { rate.setFrequency("Daily"); } } else if (totalHits > 1000L) { dur = duration.toMinutes(); if (totalHits > 1000L) { dur = duration.toMillis() / 1000L; rate.setFrequency("Second"); } else { rate.setFrequency("Minute"); } } else { rate.setFrequency("Hourly"); } rate.setValue((int) dur); } } } catch (Exception e) { LOGGER.warn("Could not set record rate: {}", e.getMessage(), e); } }
From source file:org.pentaho.hadoop.shim.common.format.avro.AvroNestedReader.java
/** * Perform Kettle type conversions for the Avro leaf field value. * * @param fieldValue the leaf value from the Avro structure * @return an Object of the appropriate Kettle type * @throws KettleException if a problem occurs */// w w w. java 2 s . co m protected Object getKettleValue(AvroInputField avroInputField, Object fieldValue) throws KettleException { switch (avroInputField.getTempValueMeta().getType()) { case ValueMetaInterface.TYPE_BIGNUMBER: return avroInputField.getTempValueMeta().getBigNumber(fieldValue); case ValueMetaInterface.TYPE_BINARY: return avroInputField.getTempValueMeta().getBinary(fieldValue); case ValueMetaInterface.TYPE_BOOLEAN: return avroInputField.getTempValueMeta().getBoolean(fieldValue); case ValueMetaInterface.TYPE_DATE: if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.INTEGER.getBaseType()) { LocalDate localDate = LocalDate.ofEpochDay(0).plusDays((Long) fieldValue); return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } else if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.STRING.getBaseType()) { Object pentahoData = null; String dateFormatStr = avroInputField.getStringFormat(); if ((dateFormatStr == null) || (dateFormatStr.trim().length() == 0)) { dateFormatStr = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK; } SimpleDateFormat datePattern = new SimpleDateFormat(dateFormatStr); try { return datePattern.parse(fieldValue.toString()); } catch (Exception e) { return null; } } return avroInputField.getTempValueMeta().getDate(fieldValue); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp((Long) fieldValue); case ValueMetaInterface.TYPE_INTEGER: return avroInputField.getTempValueMeta().getInteger(fieldValue); case ValueMetaInterface.TYPE_NUMBER: return avroInputField.getTempValueMeta().getNumber(fieldValue); case ValueMetaInterface.TYPE_STRING: return avroInputField.getTempValueMeta().getString(fieldValue); case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName(fieldValue.toString()); } catch (UnknownHostException ex) { return null; } default: return null; } }
From source file:org.silverpeas.core.util.DateUtil.java
public static LocalDate toLocalDate(Date date) { if (date == null) { return null; }// ww w. j a v a 2 s. c om return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); }
From source file:jef.tools.DateUtils.java
/** * Convert LocalDate to jud//w ww . j a v a2 s. c om * * @param date * LocalDate * @return java.util.Date */ public static Date fromLocalDate(LocalDate date) { return date == null ? null : Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); }
From source file:jef.tools.DateUtils.java
/** * Convert LocalTime to jud./* w ww. j av a2s. com*/ * * @param time * LocalTime * @return java.util.Date */ public static Date fromLocalTime(LocalTime time) { return time == null ? null : Date.from(LocalDateTime.of(LocalDate.now(), time).atZone(ZoneId.systemDefault()).toInstant()); }
From source file:jef.tools.DateUtils.java
/** * Converts LocalDateTime to java.util.Date (null safety) * @param LocalDateTime//from w w w.j a va 2 s . c o m * @return java.util.Date */ public static Date fromLocalDateTime(LocalDateTime value) { return value == null ? null : Date.from(value.atZone(ZoneId.systemDefault()).toInstant()); }
From source file:net.tourbook.photo.Photo.java
private void setupPhoto(final File photoImageFile, final IPath photoImagePath) { final String photoImageFilePathName = photoImageFile.getAbsolutePath(); final long lastModified = photoImageFile.lastModified(); imageFile = photoImageFile;//w w w .ja va 2s. com imageFileName = photoImageFile.getName(); imageFilePathName = photoImageFilePathName; imagePathName = photoImagePath.removeLastSegments(1).toOSString(); imageFileExt = photoImagePath.getFileExtension(); imageFileSize = photoImageFile.length(); _imageFileLastModified = LocalDateTime.ofInstant(// Instant.ofEpochMilli(lastModified), // ZoneOffset.UTC ZoneId.systemDefault() // ); // initially sort by file date until exif data are loaded imageExifTime = lastModified; _uniqueId = photoImageFilePathName; /* * initialize image keys and loading states */ _imageKeyThumb = getImageKeyThumb(photoImageFilePathName); _imageKeyHQ = getImageKeyHQ(photoImageFilePathName); _imageKeyOriginal = Util.computeMD5(photoImageFilePathName + "_Original");//$NON-NLS-1$ _isImageFileAvailable = photoImageFile.exists(); if (_isImageFileAvailable) { _photoLoadingStateThumb = PhotoLoadingState.UNDEFINED; _photoLoadingStateHQ = PhotoLoadingState.UNDEFINED; _photoLoadingStateOriginal = PhotoLoadingState.UNDEFINED; _isLoadingError = false; } else { _photoLoadingStateThumb = PhotoLoadingState.IMAGE_IS_INVALID; _photoLoadingStateHQ = PhotoLoadingState.IMAGE_IS_INVALID; _photoLoadingStateOriginal = PhotoLoadingState.IMAGE_IS_INVALID; _isLoadingError = true; } }