List of usage examples for java.time LocalDateTime ofInstant
public static LocalDateTime ofInstant(Instant instant, ZoneId zone)
From source file:com.thesoftwarefactory.vertx.web.model.Form.java
private static String format(Instant instant) { LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.of("+2")); return INSTANT_FORMATTER.format(ldt); }
From source file:eu.hansolo.fx.weatherfx.darksky.DarkSky.java
private LocalDateTime epochToLocalDateTime(final long TIMESTAMP) { return LocalDateTime.ofInstant(Instant.ofEpochSecond(TIMESTAMP), ZoneId.of(timeZone.getID())); }
From source file:eu.hansolo.fx.weatherfx.darksky.DarkSky.java
private LocalDateTime epochStringToLocalDateTime(final String TIME_STRING) { return LocalDateTime.ofInstant(Instant.ofEpochSecond(Long.parseLong(TIME_STRING)), ZoneId.of(timeZone.getID())); }
From source file:dk.dma.ais.packet.AisPacketCSVOutputSink.java
protected String formatEta(Date eta) { LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(eta.getTime()), ZoneId.systemDefault()); return formatEta(time.getDayOfMonth(), time.getMonthValue(), time.getHour(), time.getMinute()); }
From source file:org.codelibs.fess.web.IndexAction.java
@Execute(validator = true, input = "index") public String go() throws IOException { Map<String, Object> doc = null; try {//from ww w.j a v a 2 s . co m doc = searchService.getDocument(fieldHelper.docIdField + ":" + indexForm.docId, queryHelper.getResponseFields(), new String[] { fieldHelper.clickCountField }); } catch (final Exception e) { logger.warn("Failed to request: " + indexForm.docId, e); } if (doc == null) { errorMessage = MessageResourcesUtil.getMessage(RequestUtil.getRequest().getLocale(), "errors.docid_not_found", indexForm.docId); return "error.jsp"; } final Object urlObj = doc.get(fieldHelper.urlField); if (urlObj == null) { errorMessage = MessageResourcesUtil.getMessage(RequestUtil.getRequest().getLocale(), "errors.document_not_found", indexForm.docId); return "error.jsp"; } final String url = urlObj.toString(); if (Constants.TRUE.equals(crawlerProperties.getProperty(Constants.SEARCH_LOG_PROPERTY, Constants.TRUE))) { final String userSessionId = userInfoHelper.getUserCode(); if (userSessionId != null) { final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper(); final ClickLog clickLog = new ClickLog(); clickLog.setUrl(url); LocalDateTime now = systemHelper.getCurrentTime(); clickLog.setRequestedTime(now); clickLog.setQueryRequestedTime(LocalDateTime .ofInstant(Instant.ofEpochMilli(Long.parseLong(indexForm.rt)), ZoneId.systemDefault())); clickLog.setUserSessionId(userSessionId); clickLog.setDocId(indexForm.docId); long clickCount = 0; final Object count = doc.get(fieldHelper.clickCountField); if (count instanceof Long) { clickCount = ((Long) count).longValue(); } clickLog.setClickCount(clickCount); searchLogHelper.addClickLog(clickLog); } } String hash; if (StringUtil.isNotBlank(indexForm.hash)) { final String value = URLUtil.decode(indexForm.hash, Constants.UTF_8); final StringBuilder buf = new StringBuilder(value.length() + 100); for (final char c : value.toCharArray()) { if (CharUtil.isUrlChar(c) || c == ' ') { buf.append(c); } else { try { buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8)); } catch (final UnsupportedEncodingException e) { // NOP } } } hash = buf.toString(); } else { hash = StringUtil.EMPTY; } if (isFileSystemPath(url)) { if (Constants.TRUE .equals(crawlerProperties.getProperty(Constants.SEARCH_FILE_PROXY_PROPERTY, Constants.TRUE))) { final CrawlingConfigHelper crawlingConfigHelper = ComponentUtil.getCrawlingConfigHelper(); try { crawlingConfigHelper.writeContent(doc); return null; } catch (final Exception e) { logger.error("Failed to load: " + doc, e); errorMessage = MessageResourcesUtil.getMessage(RequestUtil.getRequest().getLocale(), "errors.not_load_from_server", url); return "error.jsp"; } } else if (Constants.TRUE .equals(crawlerProperties.getProperty(Constants.SEARCH_DESKTOP_PROPERTY, Constants.FALSE))) { final String path = url.replaceFirst("file:/+", "//"); final File file = new File(path); if (!file.exists()) { errorMessage = MessageResourcesUtil.getMessage(RequestUtil.getRequest().getLocale(), "errors.not_found_on_file_system", url); return "error.jsp"; } final Desktop desktop = Desktop.getDesktop(); try { desktop.open(file); } catch (final Exception e) { errorMessage = MessageResourcesUtil.getMessage(RequestUtil.getRequest().getLocale(), "errors.could_not_open_on_system", url); logger.warn("Could not open " + path, e); return "error.jsp"; } ResponseUtil.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT); return null; } else { ResponseUtil.getResponse().sendRedirect(url + hash); } } else { ResponseUtil.getResponse().sendRedirect(url + hash); } return null; }
From source file:com.gnadenheimer.mg.utils.Utils.java
public void backUpIfOld() { try {//from w ww . j a va 2s. c o m Path dir = Paths.get(getPersistenceMap().get("backUpDir")); // specify your directory Optional<Path> lastFilePath = Files.list(dir) // here we get the stream with full directory listing .filter(f -> Files.isDirectory(f)) // exclude files from listing .max(Comparator.comparingLong(f -> f.toFile().lastModified())); // finally get the last file using simple comparator by lastModified field if (lastFilePath.isPresent()) // your folder may be empty { FileTime fileTime = Files.getLastModifiedTime(lastFilePath.get()); Long age = DAYS.between(LocalDateTime.ofInstant(fileTime.toInstant(), ZoneOffset.UTC), LocalDateTime.now()); if (age > 7) { exectueBackUp(getPersistenceMap().get("backUpDir")); } } else { exectueBackUp(getPersistenceMap().get("backUpDir")); } } catch (Exception ex) { LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); } }
From source file:com.gnadenheimer.mg.utils.Utils.java
/** * Delete AutoBackUps if older than 60 days *///from w w w.j a v a2 s. co m public void deleteOldBackUps() { try { Path dir = Paths.get(getPersistenceMap().get("backUpDir")); // specify your directory Optional<Path> lastFilePath = Files.list(dir) // here we get the stream with full directory listing .filter(f -> Files.isDirectory(f)) // exclude files from listing .min(Comparator.comparingLong(f -> f.toFile().lastModified())); // finally get the last file using simple comparator by lastModified field if (lastFilePath.isPresent()) // your folder may be empty { FileTime fileTime = Files.getLastModifiedTime(lastFilePath.get()); Long age = DAYS.between(LocalDateTime.ofInstant(fileTime.toInstant(), ZoneOffset.UTC), LocalDateTime.now()); if (age > 30) { Files.walk(lastFilePath.get(), FileVisitOption.FOLLOW_LINKS).sorted(Comparator.reverseOrder()) .map(Path::toFile).peek(System.out::println).forEach(File::delete); deleteOldBackUps(); } } } catch (Exception ex) { LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); } }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTimeslotList() { List<Timeslot> timeslotList = new ArrayList<>(); Map<Timeslot, List<Room>> timeslotToAvailableRoomsMap = new HashMap<>(); Map<Pair<LocalDateTime, LocalDateTime>, Timeslot> startAndEndTimeToTimeslotMap = new HashMap<>(); Long timeSlotId = 0L;/*from w w w . j ava2 s .c o m*/ String schedulesUrl = conferenceBaseUrl + "/schedules/"; LOGGER.debug("Sending a request to: " + schedulesUrl); JsonArray daysArray = readJson(schedulesUrl, JsonReader::readObject).getJsonArray("links"); for (int i = 0; i < daysArray.size(); i++) { JsonObject dayObject = daysArray.getJsonObject(i); String dayUrl = dayObject.getString("href"); LOGGER.debug("Sending a request to: " + dayUrl); JsonArray daySlotsArray = readJson(dayUrl, JsonReader::readObject).getJsonArray("slots"); for (int j = 0; j < daySlotsArray.size(); j++) { JsonObject timeslotObject = daySlotsArray.getJsonObject(j); LocalDateTime startDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("fromTimeMillis").longValue()), ZoneId.of(ZONE_ID)); LocalDateTime endDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("toTimeMillis").longValue()), ZoneId.of(ZONE_ID)); Room room = roomIdToRoomMap.get(timeslotObject.getString("roomId")); if (room == null) { throw new IllegalStateException("The timeslot (" + timeslotObject.getString("slotId") + ") has a roomId (" + timeslotObject.getString("roomId") + ") that does not exist in the rooms list"); } // Assuming slotId is of format: tia_room6_monday_12_.... take only "tia" String talkTypeName = timeslotObject.getString("slotId").split("_")[0]; TalkType timeslotTalkType = talkTypeNameToTalkTypeMap.get(talkTypeName); if (Arrays.asList(IGNORED_TALK_TYPES).contains(talkTypeName)) { continue; } Timeslot timeslot; if (startAndEndTimeToTimeslotMap.keySet().contains(Pair.of(startDateTime, endDateTime))) { timeslot = startAndEndTimeToTimeslotMap.get(Pair.of(startDateTime, endDateTime)); timeslotToAvailableRoomsMap.get(timeslot).add(room); if (timeslotTalkType != null) { timeslot.getTalkTypeSet().add(timeslotTalkType); } } else { timeslot = new Timeslot(timeSlotId++); timeslot.withStartDateTime(startDateTime).withEndDateTime(endDateTime) .withTalkTypeSet(timeslotTalkType == null ? new HashSet<>() : new HashSet<>(Arrays.asList(timeslotTalkType))); timeslot.setTagSet(new HashSet<>()); timeslotList.add(timeslot); timeslotToAvailableRoomsMap.put(timeslot, new ArrayList<>(Arrays.asList(room))); startAndEndTimeToTimeslotMap.put(Pair.of(startDateTime, endDateTime), timeslot); } if (!timeslotObject.isNull("talk")) { scheduleTalk(timeslotObject, room, timeslot); } for (TalkType talkType : timeslot.getTalkTypeSet()) { talkType.getCompatibleTimeslotSet().add(timeslot); } timeslotTalkTypeToTotalMap.merge(talkTypeName, 1, Integer::sum); } } for (Room room : solution.getRoomList()) { room.setUnavailableTimeslotSet(timeslotList.stream() .filter(timeslot -> !timeslotToAvailableRoomsMap.get(timeslot).contains(room)) .collect(Collectors.toSet())); } solution.setTimeslotList(timeslotList); }
From source file:ru.anr.base.BaseParent.java
/** * @param date// www . j a v a 2s. c om * Date * @param locale * Locale * @return formatted date */ public static String formatDate(long date, String locale) { return DateTimeFormatter .ofPattern("ru_RU".equals(locale) ? "dd.MM.yyyy HH:mm:ss z" : "dd/MM/yyyy HH:mm:ss z") .withZone(ZoneOffset.systemDefault()) .format(LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.systemDefault())); }
From source file:ru.anr.base.BaseParent.java
/** * @param pattern// www . j av a 2 s. c om * patter * @param date * date * @return formatted date */ public static String formatDate(String pattern, Calendar date) { return DateTimeFormatter.ofPattern(pattern).format( LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTimeInMillis()), ZoneId.systemDefault())); }