List of usage examples for java.time ZoneOffset UTC
ZoneOffset UTC
To view the source code for java.time ZoneOffset UTC.
Click Source Link
From source file:com.example.app.support.service.AppUtil.java
/** * Convert the given ZonedDateTime to a UTC date for persistence * * @param dt the ZonedDateTime to convert to UTC * * @return a Date object that represents the same instant as the ZonedDateTime, but at UTC. */// w ww . j a va2s. co m @Nullable @Contract(value = "!null->!null;null->null", pure = true) public static Date convertForPersistence(@Nullable ZonedDateTime dt) { if (dt == null) return null; ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC); return new Date(atUtc.toInstant().toEpochMilli()); }
From source file:org.apache.solr.client.solrj.io.stream.eval.TemporalEvaluatorsTest.java
@Test public void testFunctionsLocalDateTime() throws Exception { LocalDateTime localDateTime = LocalDateTime.of(2017, 12, 5, 23, 59); Date aDate = Date.from(localDateTime.atZone(ZoneOffset.UTC).toInstant()); testFunction("year(a)", localDateTime, 2017); testFunction("month(a)", localDateTime, 12); testFunction("day(a)", localDateTime, 5); testFunction("hour(a)", localDateTime, 23); testFunction("minute(a)", localDateTime, 59); testFunction("epoch(a)", localDateTime, aDate.getTime()); }
From source file:com.thinkbiganalytics.nifi.v2.ingest.GetTableData.java
public static Date toDate(LocalDateTime dateTime) { return dateTime == null ? new Date(0L) : Date.from(dateTime.toInstant(ZoneOffset.UTC)); }
From source file:com.example.app.profile.model.ProfileDAO.java
/** * Create an save a ProfileDatedRecord for the given Profile, category, and subcategory. * Uses LocalDateTime.now() for the date, at UTC. * * @param profile the Profile//w w w. ja v a 2s . co m * @param category the category * @param subCategory the subcategory * * @return the new ProfileDatedRecord */ public ProfileDatedRecord createProfileDatedRecord(Profile profile, String category, @Nullable String subCategory) { ProfileDatedRecord pdr = new ProfileDatedRecord(); pdr.setProfile(profile); pdr.setDate(convertForPersistence(ZonedDateTime.now(ZoneOffset.UTC))); pdr.setCategory(category); pdr.setSubCategory(subCategory); saveProfileDatedRecord(pdr); return pdr; }
From source file:com.example.app.support.service.AppUtil.java
/** * Convert the given Date from UTC to a ZonedDateTime at the given TimeZone * * @param date the UTC date//from ww w .ja v a 2 s .c om * @param zone the TimeZone to convert the time to * * @return a ZonedDateTime that represents the same instant as the UTC date, but at the given TimeZone. */ @Nullable @Contract(value = "null,_->null;_,null->null;!null,!null->!null", pure = true) public static ZonedDateTime convertFromPersisted(@Nullable Date date, @Nullable TimeZone zone) { if (date == null || zone == null) return null; ZonedDateTime from = ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC); return from.withZoneSameInstant(zone.toZoneId()); }
From source file:no.imr.stox.functions.acoustic.PgNapesIO.java
public static void convertPgNapesToLuf20(String path, String fileName, String outFileName) { try {/*from ww w .ja v a2 s. c om*/ List<String> acList = Files.readAllLines(Paths.get(path + "/" + fileName + ".txt")); List<String> acVList = Files.readAllLines(Paths.get(path + "/" + fileName + "Values.txt")); if (acList.isEmpty() || acVList.isEmpty()) { return; } acList.remove(0); acVList.remove(0); List<DistanceBO> dList = acList.stream().map(s -> { DistanceBO d = new DistanceBO(); String[] str = s.split("\t", 14); d.setNation(str[0]); d.setPlatform(str[1]); d.setCruise(str[2]); d.setLog_start(Conversion.safeStringtoDoubleNULL(str[3])); d.setStart_time(Date.from(LocalDateTime.of(Conversion.safeStringtoIntegerNULL(str[4]), Conversion.safeStringtoIntegerNULL(str[5]), Conversion.safeStringtoIntegerNULL(str[6]), Conversion.safeStringtoIntegerNULL(str[7]), Conversion.safeStringtoIntegerNULL(str[8]), 0) .toInstant(ZoneOffset.UTC))); d.setLat_start(Conversion.safeStringtoDoubleNULL(str[9])); d.setLon_start(Conversion.safeStringtoDoubleNULL(str[10])); d.setIntegrator_dist(Conversion.safeStringtoDoubleNULL(str[11])); FrequencyBO freq = new FrequencyBO(); d.getFrequencies().add(freq); freq.setTranceiver(1); // implicit in pgnapes freq.setUpper_interpret_depth(0d); freq.setUpper_integrator_depth(0d); freq.setDistance(d); freq.setFreq(Conversion.safeStringtoIntegerNULL(str[12])); freq.setThreshold(Conversion.safeStringtoDoubleNULL(str[13])); return d; }).collect(Collectors.toList()); // Fill in sa values acVList.forEach(s -> { String[] str = s.split("\t", 11); String cruise = str[2]; Double log = Conversion.safeStringtoDoubleNULL(str[3]); Integer year = Conversion.safeStringtoIntegerNULL(str[4]); Integer month = Conversion.safeStringtoIntegerNULL(str[5]); Integer day = Conversion.safeStringtoIntegerNULL(str[6]); if (log == null || year == null || month == null || day == null) { return; } DistanceBO d = dList.parallelStream().filter(di -> { if (di.getCruise() == null || di.getLog_start() == null || di.getStart_time() == null) { return false; } LocalDate ld = di.getStart_time().toInstant().atZone(ZoneOffset.UTC).toLocalDate(); return cruise.equals(di.getCruise()) && log.equals(di.getLog_start()) && year.equals(ld.getYear()) && month.equals(ld.getMonthValue()) && day.equals(ld.getDayOfMonth()); }).findFirst().orElse(null); if (d == null) { return; } FrequencyBO freq = d.getFrequencies().get(0); String species = str[7]; Integer acocat = PgNapesEchoConvert.getAcoCatFromPgNapesSpecies(species); Double chUppDepth = Conversion.safeStringtoDoubleNULL(str[8]); Double chLowDepth = Conversion.safeStringtoDoubleNULL(str[9]); Double sa = Conversion.safeStringtoDoubleNULL(str[10]); if (acocat == null || sa == null || sa == 0d || chLowDepth == null || chUppDepth == null) { return; } if (d.getPel_ch_thickness() == null) { d.setPel_ch_thickness(chLowDepth - chUppDepth); } Integer ch = (int) (chLowDepth / d.getPel_ch_thickness() + 0.5); SABO sabo = new SABO(); sabo.setFrequency(freq); freq.getSa().add(sabo); sabo.setAcoustic_category(acocat + ""); sabo.setCh_type("P"); sabo.setCh(ch); sabo.setSa(sa); }); // Calculate number of pelagic channels /*dList.stream().forEach(d -> { FrequencyBO f = d.getFrequencies().get(0); Integer minCh = f.getSa().stream().map(SABO::getCh).min(Integer::compare).orElse(null); Integer maxCh = f.getSa().stream().map(SABO::getCh).max(Integer::compare).orElse(null); if (maxCh != null && minCh != null) { f.setNum_pel_ch(maxCh - minCh + 1); } });*/ if (dList.isEmpty()) { return; } DistanceBO d = dList.get(0); String cruise = d.getCruise(); String nation = d.getNation(); String pl = d.getPlatform(); ListUser20Writer.export(cruise, nation, pl, path + "/" + cruise + outFileName + ".xml", dList); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gov.osti.search.SearchData.java
/** * Translate this Bean into a SOLR query parameter set. * * @return a SOLR query parameter "q" for these attributes; default to "*:*" * (everything) if nothing is set/*from w w w . j a va 2 s. c o m*/ */ public String toQ() { StringBuilder q = new StringBuilder(); DateTimeFormatter SOLR_DATE_FORMAT = DateTimeFormatter.ISO_INSTANT; if (!StringUtils.isEmpty(getAllFields())) { if (q.length() > 0) q.append(" "); q.append("_text_:(").append(escape(getAllFields(), true)).append(")"); } if (null != getAccessibility()) { StringBuilder codes = new StringBuilder(); for (String code : getAccessibility()) { if (codes.length() > 0) codes.append(" OR "); codes.append("accessibility:").append(code); } if (codes.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(codes.toString()).append(")"); } } // support ARRAY of SOFTWARE TYPES if (null != getSoftwareType()) { StringBuilder types = new StringBuilder(); for (String type : getSoftwareType()) { if (types.length() > 0) types.append(" OR "); types.append("softwareType:").append(type); } if (types.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(types.toString()).append(")"); } } if (null != getProgrammingLanguages()) { StringBuilder values = new StringBuilder(); for (String programmingLanguage : getProgrammingLanguages()) { if (values.length() > 0) values.append(" OR "); values.append("programmingLanguages:\"").append(escapeToken(programmingLanguage)).append("\""); } if (values.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(values.toString()).append(")"); } } if (!StringUtils.isEmpty(getKeywords())) { if (q.length() > 0) q.append(" "); q.append("keywords:(").append(escape(getKeywords(), true)).append(")"); } if (null != getProjectKeywords()) { StringBuilder values = new StringBuilder(); for (String projectKeyword : getProjectKeywords()) { if (values.length() > 0) values.append(" OR "); values.append("projectKeywords:\"").append(escapeToken(projectKeyword)).append("\""); } if (values.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(values.toString()).append(")"); } } if (null != getLicenses()) { StringBuilder values = new StringBuilder(); for (String license : getLicenses()) { if (values.length() > 0) values.append(" OR "); values.append("licenses:\"").append(escapeToken(license)).append("\""); } if (values.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(values.toString()).append(")"); } } if (!StringUtils.isEmpty(getBiblioData())) { if (q.length() > 0) q.append(" "); q.append("_text_:(").append(escape(getBiblioData(), true)).append(")"); } if (!StringUtils.isEmpty(getOrcid())) { if (q.length() > 0) q.append(" "); q.append("_orcids:(").append(escape(getOrcid())).append(")"); } if (!StringUtils.isEmpty(getDevelopersContributors())) { if (q.length() > 0) q.append(" "); q.append("_names:(").append(escape(getDevelopersContributors(), true)).append(")"); } if (!StringUtils.isEmpty(getIdentifiers())) { if (q.length() > 0) q.append(" "); q.append("_id_numbers:(").append(escape(getIdentifiers())).append(")"); } if (null != getResearchOrganization()) { StringBuilder values = new StringBuilder(); for (String org : getResearchOrganization()) { if (values.length() > 0) values.append(" OR "); values.append("researchOrganizations.organizationName:\"").append(escape(org)).append("\""); } if (values.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(values.toString()).append(")"); } } if (null != getSponsoringOrganization()) { StringBuilder values = new StringBuilder(); for (String org : getSponsoringOrganization()) { if (values.length() > 0) values.append(" OR "); values.append("sponsoringOrganizations.organizationName:\"").append(escape(org)).append("\""); } if (values.length() > 0) { if (q.length() > 0) q.append(" "); q.append("(").append(values.toString()).append(")"); } } if (!StringUtils.isEmpty(getSoftwareTitle())) { if (q.length() > 0) q.append(" "); q.append("softwareTitle:(").append(escape(getSoftwareTitle(), true)).append(")"); } if (null != getDateEarliest()) { if (q.length() > 0) q.append(" "); q.append("releaseDate:[").append(SOLR_DATE_FORMAT.format( getDateEarliest().toInstant().atOffset(ZoneOffset.UTC).withHour(0).withMinute(0).withSecond(0))) .append(" TO *]"); } if (null != getDateLatest()) { if (q.length() > 0) q.append(" "); q.append("releaseDate:[* TO ").append(SOLR_DATE_FORMAT.format(getDateLatest().toInstant() .atOffset(ZoneOffset.UTC).withHour(23).withMinute(59).withSecond(59))).append("]"); } return (0 == q.length()) ? "*:*" : q.toString(); }
From source file:serposcope.controllers.google.GoogleTargetController.java
protected Result renderChart(Group group, GoogleTarget target, List<GoogleSearch> searches, List<Run> runs, LocalDate minDay, LocalDate maxDay, LocalDate startDate, LocalDate endDate) { String display = "chart"; StringBuilder builder = new StringBuilder("{\"searches\": ["); for (GoogleSearch search : searches) { builder.append("\"").append(StringEscapeUtils.escapeJson(search.getKeyword())).append("\","); }// w ww . j a va 2 s.c o m builder.setCharAt(builder.length() - 1, ']'); builder.append(",\"ranks\": ["); int maxRank = 0; for (Run run : runs) { builder.append("\n\t[").append(run.getStarted().toEpochSecond(ZoneOffset.UTC) * 1000l).append(","); // calendar builder.append("null,"); Map<Integer, GoogleRank> ranks = googleDB.rank.list(run.getId(), group.getId(), target.getId()).stream() .collect(Collectors.toMap((g) -> g.googleSearchId, Function.identity())); for (GoogleSearch search : searches) { GoogleRank fullRank = ranks.get(search.getId()); // GoogleRank fullRank = googleDB.rank.getFull(run.getId(), group.getId(), target.getId(), search.getId()); if (fullRank != null && fullRank.rank != GoogleRank.UNRANKED && fullRank.rank > maxRank) { maxRank = fullRank.rank; } builder.append(fullRank == null || fullRank.rank == GoogleRank.UNRANKED ? "null" : fullRank.rank) .append(','); } builder.setCharAt(builder.length() - 1, ']'); builder.append(","); } builder.setCharAt(builder.length() - 1, ']'); builder.append(",\n\"maxRank\": ").append(maxRank).append("}"); List<Event> events = baseDB.event.list(group, startDate, endDate); String jsonEvents = null; try { jsonEvents = objectMapper.writeValueAsString(events); } catch (JsonProcessingException ex) { jsonEvents = "[]"; } Map<Integer, GoogleBest> bestRanks = new HashMap<>(); for (GoogleSearch search : searches) { bestRanks.put(search.getId(), googleDB.rank.getBest(target.getGroupId(), target.getId(), search.getId())); } return Results.ok().template("/serposcope/views/google/GoogleTargetController/" + display + ".ftl.html") .render("target", target).render("searches", searches).render("startDate", startDate.toString()) .render("endDate", endDate.toString()).render("minDate", minDay).render("maxDate", maxDay) .render("display", display).render("ranksJson", builder.toString()) .render("eventsJson", jsonEvents); }