List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:no.asgari.civilization.server.action.GameAction.java
/** * Creating PbfDTO so to not include every players Ghand and information * * @param pbf - the PBF//from w w w . j a v a 2 s .com * @return PbfDto */ private static PbfDTO createPbfDTO(PBF pbf) { PbfDTO dto = new PbfDTO(); dto.setType(pbf.getType()); dto.setId(pbf.getId()); dto.setName(pbf.getName()); dto.setActive(pbf.isActive()); long created = pbf.getCreated().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); dto.setCreated(created); dto.setNumOfPlayers(pbf.getNumOfPlayers()); dto.setPlayers(pbf.getPlayers().stream().map(p -> createPlayerDTO(p, pbf.getId())).collect(toList())); dto.setNameOfUsersTurn(pbf.getNameOfUsersTurn()); return dto; }
From source file:com.buffalokiwi.api.APIDate.java
/** * Convert whatever date this is to the system zone * @return system date/time/*from ww w . j a va 2s.c o m*/ */ @Override public Date toLocalDate() { return Date.from(date.withZoneSameInstant(ZoneId.systemDefault()).toInstant()); }
From source file:org.codice.ddf.security.idp.client.IdpMetadataTest.java
/** * Return a modified version of the (XML) input. The cache duration and valid-until time are * modified to match the respective input parameters. If null is passed for the cache duration, * the value of the cache duration already in the XML is used. Because of how the substitution * works, this method can only be called only once per test. Otherwise, it will create multiple * "validUntil" XML attributes.//from w w w .j av a 2 s . c o m * * @param validUntil the validUntil instant * @param xml the SAML entity description document * @return SAML entity description document with a validUntil date */ private String setValidUntil(Instant validUntil, String iso8601Duration, String xml) { Pattern pattern = Pattern.compile("cacheDuration=\"(\\w*)\""); Matcher matcher = pattern.matcher(xml); assertThat("Cannot setup test data - precondition not met", matcher.find(), is(true)); assertThat("Cannot setup test data - precondition not met", matcher.groupCount(), is(1)); String duration = iso8601Duration == null ? matcher.group(1) : iso8601Duration; DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; ZonedDateTime temporalAccessor = ZonedDateTime.ofInstant(validUntil, ZoneId.systemDefault()); String isoTimestamp = formatter.format(temporalAccessor); return xml.replaceFirst(CACHE_DURATION_REGEX, String.format("cacheDuration=\"%s\" validUntil=\"%s\"", duration, isoTimestamp)); }
From source file:org.tightblog.rendering.requests.WeblogSearchRequest.java
/** * Create weblog entries for each result found. *///from w ww.j a va 2 s.com Map<LocalDate, TreeSet<WeblogEntry>> convertHitsToEntries(ScoreDoc[] hits, SearchTask searchTask) { Map<LocalDate, TreeSet<WeblogEntry>> results = new HashMap<>(); // determine offset and limit this.offset = getPageNum() * RESULTS_PER_PAGE; if (this.offset >= hits.length) { this.offset = 0; } this.limit = RESULTS_PER_PAGE; if (this.offset + this.limit > hits.length) { this.limit = hits.length - this.offset; } WeblogEntry entry; Document doc; for (int i = offset; i < offset + limit; i++) { try { doc = searchTask.getSearcher().doc(hits[i].doc); } catch (IOException e) { log.warn("IOException processing {}", hits[i].doc, e); continue; } entry = searchModel.getWeblogEntryRepository() .findByIdOrNull(doc.getField(FieldConstants.ID).stringValue()); if (entry != null && WeblogEntry.PubStatus.PUBLISHED.equals(entry.getStatus())) { LocalDate pubDate = entry.getPubTime().atZone(ZoneId.systemDefault()).toLocalDate(); // ensure we do not get duplicates from Lucene by using a set collection. results.putIfAbsent(pubDate, new TreeSet<>(Comparator.comparing(WeblogEntry::getPubTime).reversed() .thenComparing(WeblogEntry::getTitle))); results.get(pubDate).add(entry); } } return results; }
From source file:dk.dbc.rawrepo.oai.OAIIdentifierCollection.java
/** * Fetch identifiers from database// w ww . j a va2s .c o m * * json argument is object with: null null null null null {@literal * f: fromTimestamp* * u: untilTimestamp* * m: metadataPrefix * o: fromOffset (how many records with fromTimestamp has been seen)* * s: set* * } * * @param json as described * @param limit how many records to fetch * @return json as described or null if no more records */ @SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") public ObjectNode fetch(ObjectNode json, int limit) { log.debug("limit = " + limit); StringBuilder sb = new StringBuilder(); String set = json.path("s").asText(null); String from = json.path("f").asText(null); String until = json.path("u").asText(null); String metadataPrefix = json.path("m").asText(""); int offset = json.path("o").asInt(0); sb.append("SELECT pid, changed, deleted FROM oairecords JOIN oairecordsets USING (pid) WHERE"); if (set != null) { sb.append(" setSpec = ?"); } else if (allowedSets.isEmpty()) { return null; } else { sb.append(" setSpec IN ('"); sb.append(allowedSets.stream().sorted().collect(Collectors.joining("', '"))); sb.append("')"); } sb.append(" AND ? in (SELECT prefix FROM oaiformats)"); if (from != null) { sb.append(" AND"); if (from.contains(".")) { sb.append( " DATE_TRUNC('milliseconds', changed) >= DATE_TRUNC('milliseconds', ?::timestamp AT TIME ZONE 'UTC')"); } else if (from.contains("T")) { sb.append( " DATE_TRUNC('second', changed) >= DATE_TRUNC('second', ?::timestamp AT TIME ZONE 'UTC')"); } else { sb.append(" DATE_TRUNC('day', changed) >= DATE_TRUNC('day', ?::timestamp AT TIME ZONE 'UTC')"); } } if (until != null) { sb.append(" AND"); if (until.contains(".")) { sb.append( " DATE_TRUNC('milliseconds', changed) <= DATE_TRUNC('milliseconds', ?::timestamp AT TIME ZONE 'UTC')"); } else if (until.contains("T")) { sb.append( " DATE_TRUNC('second', changed) <= DATE_TRUNC('second', ?::timestamp AT TIME ZONE 'UTC')"); } else { sb.append(" DATE_TRUNC('day', changed) <= DATE_TRUNC('day', ?::timestamp AT TIME ZONE 'UTC')"); } } sb.append(" GROUP BY pid"); if (set != null) { sb.append(", gone"); } sb.append(" ORDER BY changed, pid OFFSET ? LIMIT ?"); String query = sb.toString(); log.debug("query = " + query); sb = new StringBuilder(); sb.append("SELECT setSpec FROM oairecordsets WHERE pid = ? AND setSpec IN ('") .append(allowedSets.stream().sorted().collect(Collectors.joining("', '"))) .append("') AND NOT gone ORDER BY setSpec"); String setQuery = sb.toString(); Timestamp last = null; int row = 0; try (PreparedStatement stmt = connection.prepareStatement(query); PreparedStatement sets = connection.prepareStatement(setQuery)) { int i = 1; if (set != null) { stmt.setString(i++, set); } stmt.setString(i++, metadataPrefix); if (from != null) { stmt.setString(i++, from); } if (until != null) { stmt.setString(i++, until); } stmt.setInt(i++, offset); stmt.setInt(i++, limit + 1); try (ResultSet resultSet = stmt.executeQuery()) { while (resultSet.next()) { row++; String pid = resultSet.getString(1); Timestamp changed = resultSet.getTimestamp(2); Boolean deleted = resultSet.getBoolean(3); if (row <= limit) { OAIIdentifier oaiRecord = new OAIIdentifier(pid, changed, deleted); sets.setString(1, pid); try (ResultSet setsResult = sets.executeQuery()) { while (setsResult.next()) { oaiRecord.add(setsResult.getString(1)); } } if (oaiRecord.isEmpty() && !oaiRecord.isDeleted()) { oaiRecord = new OAIIdentifier(pid, changed, true); } add(oaiRecord); if (changed.equals(last)) { offset++; } else { last = changed; offset = 1; } } else { ObjectNode obj = OBJECT_MAPPER.createObjectNode(); String continueFrom = changed.toInstant().atZone(ZoneId.systemDefault()) .format(DateTimeFormatter.ISO_INSTANT); obj.put("f", continueFrom); if (changed.equals(last)) { obj.put("o", offset); } if (until != null) { obj.put("u", until); } if (set != null) { obj.put("s", set); } if (metadataPrefix != null) { obj.put("m", metadataPrefix); } log.debug("continueFrom = " + obj); return obj; } } } } catch (SQLException ex) { log.error("Exception: " + ex.getMessage()); log.debug("Exception:", ex); throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR, "Internal Error"); } return null; }
From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java
private Date getFinalDate(final Date initialDate, final int hour) { final LocalDate today = LocalDate.now(); LocalDateTime finalDateTime = null; if (DateUtils.isSameDay(initialDate, new Date())) { finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0)); } else {//from www .j av a 2 s . co m finalDateTime = today.atTime(LocalTime.of(hour, 0)); } final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault()); return Date.from(zdt.toInstant()); }
From source file:fi.vrk.xroad.catalog.lister.JaxbConverter.java
protected XMLGregorianCalendar toXmlGregorianCalendar(LocalDateTime localDateTime) { if (localDateTime == null) { return null; } else {/*from ww w . jav a 2s. c om*/ GregorianCalendar cal = GregorianCalendar.from(localDateTime.atZone(ZoneId.systemDefault())); XMLGregorianCalendar xc = null; try { xc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (DatatypeConfigurationException e) { throw new CatalogListerRuntimeException("Cannot instantiate DatatypeFactory", e); } return xc; } }
From source file:org.eclipse.smarthome.binding.openweathermap.internal.handler.AbstractOpenWeatherMapHandler.java
protected State getDateTimeTypeState(@Nullable Integer value) { return (value == null) ? UnDefType.UNDEF : new DateTimeType( ZonedDateTime.ofInstant(Instant.ofEpochSecond(value.longValue()), ZoneId.systemDefault())); }
From source file:fr.pilato.elasticsearch.crawler.fs.framework.FsCrawlerUtil.java
public static LocalDateTime getCreationTime(File file) { LocalDateTime time;//from ww w. ja v a 2 s . co m try { Path path = Paths.get(file.getAbsolutePath()); BasicFileAttributes fileattr = Files.getFileAttributeView(path, BasicFileAttributeView.class) .readAttributes(); time = LocalDateTime.ofInstant(fileattr.creationTime().toInstant(), ZoneId.systemDefault()); } catch (Exception e) { time = null; } return time; }