List of usage examples for java.time.temporal ChronoUnit SECONDS
ChronoUnit SECONDS
To view the source code for java.time.temporal ChronoUnit SECONDS.
Click Source Link
From source file:dk.dbc.rawrepo.oai.ResumptionToken.java
/** * Construct a ResumptionToken from a json object * * @param obj json value/* www .ja va 2 s . c o m*/ * @param validHours timeout * @return Resumption token to add to an oaipmh request */ public static ResumptionTokenType toToken(ObjectNode obj, int validHours) { if (obj == null) { return null; } ResumptionTokenType token = OBJECT_FACTORY.createResumptionTokenType(); Instant timeout = Instant.now().plus(validHours, ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS); XMLGregorianCalendar date = OAIResource.gregorianTimestamp(timeout); token.setExpirationDate(date); token.setValue(encode(obj, validHours)); return token; }
From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java
/** The simplest date parsing utility - only handles daily/hourly/monthly type strings (1d, d, daily, day - etc). Note "m" is ambiguous and not supported, use "min" or "month" * @param human_readable_period - daily/hourly/monthly type strings (1d, d, daily, day - etc). Note "m" is ambiguous and not supported, use "min" or "month" * @return a ChronoUnit if successful, else a generic error string *///from w w w . j a v a2 s . com public static Validation<String, ChronoUnit> getTimePeriod(final String human_readable_period) { return Patterns .match(Optional.ofNullable(human_readable_period).orElse("").toLowerCase().replaceAll("\\s+", "")) .<Validation<String, ChronoUnit>>andReturn() .when(d -> d.equals("1d"), __ -> Validation.success(ChronoUnit.DAYS)) .when(d -> d.equals("d"), __ -> Validation.success(ChronoUnit.DAYS)) .when(d -> d.equals("1day"), __ -> Validation.success(ChronoUnit.DAYS)) .when(d -> d.equals("day"), __ -> Validation.success(ChronoUnit.DAYS)) .when(d -> d.equals("daily"), __ -> Validation.success(ChronoUnit.DAYS)) .when(d -> d.equals("1w"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("w"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("1wk"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("wk"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("1week"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("week"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("weekly"), __ -> Validation.success(ChronoUnit.WEEKS)) .when(d -> d.equals("1month"), __ -> Validation.success(ChronoUnit.MONTHS)) .when(d -> d.equals("month"), __ -> Validation.success(ChronoUnit.MONTHS)) .when(d -> d.equals("monthly"), __ -> Validation.success(ChronoUnit.MONTHS)) .when(d -> d.equals("1sec"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("sec"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("1s"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("s"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("1second"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("second"), __ -> Validation.success(ChronoUnit.SECONDS)) .when(d -> d.equals("1min"), __ -> Validation.success(ChronoUnit.MINUTES)) .when(d -> d.equals("min"), __ -> Validation.success(ChronoUnit.MINUTES)) .when(d -> d.equals("1minute"), __ -> Validation.success(ChronoUnit.MINUTES)) .when(d -> d.equals("minute"), __ -> Validation.success(ChronoUnit.MINUTES)) .when(d -> d.equals("1h"), __ -> Validation.success(ChronoUnit.HOURS)) .when(d -> d.equals("h"), __ -> Validation.success(ChronoUnit.HOURS)) .when(d -> d.equals("1hour"), __ -> Validation.success(ChronoUnit.HOURS)) .when(d -> d.equals("hour"), __ -> Validation.success(ChronoUnit.HOURS)) .when(d -> d.equals("hourly"), __ -> Validation.success(ChronoUnit.HOURS)) .when(d -> d.equals("1y"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("y"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("1year"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("year"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("1yr"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("yr"), __ -> Validation.success(ChronoUnit.YEARS)) .when(d -> d.equals("yearly"), __ -> Validation.success(ChronoUnit.YEARS)) .otherwise(__ -> Validation .fail(ErrorUtils.get(ErrorUtils.INVALID_DATETIME_FORMAT, human_readable_period))); }
From source file:com.example.oauth.AccessToken.java
@Override public int getExpiresIn() { final OffsetDateTime now = OffsetDateTime.now(); final Duration expiredIn = Duration.between(now, expiration); return (int) expiredIn.get(ChronoUnit.SECONDS); }
From source file:com.teradata.benchto.driver.TestConfig.java
@Primary @Bean// ww w.j a v a 2 s. co m public QueryExecutionDriver queryExecutionDriver() { return new QueryExecutionDriver() { @Override public QueryExecutionResult execute(QueryExecution queryExecution, Connection connection) throws SQLException { QueryExecutionResult executionResult = super.execute(queryExecution, connection); // Queries in tests need to seemingly take non-zero duration (measured with seconds precision), even if Graphite precision is subtracted. ZonedDateTime newStart = ((ZonedDateTime) ReflectionTestUtils.getField(executionResult, "utcStart")) .minus(2, ChronoUnit.SECONDS); ReflectionTestUtils.setField(executionResult, "utcStart", newStart); return executionResult; } }; }
From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java
@Test public void testSerializeToJson_ComplexerObject() throws Exception { Snapshot snapshot = Snapshot.builder(Instant.EPOCH, null).withStartTime(Instant.EPOCH) .withEndTime(Instant.EPOCH) .withTeamStates(new TeamStates().setStateForTeam(0, new TeamState() .addTagSeenEvent(new Snapshot(Instant.EPOCH), new TagSeenEvent(Instant.EPOCH, new TagId("ABCD"), 0, 0L)) .addTagSeenEvent(null, // TODO: It's not really clean that we're passing null here, // but it should work fine nonetheless new TagSeenEvent(Instant.EPOCH.plus(1000, ChronoUnit.SECONDS), new TagId("ABCD"), 0, 1L)))) .withTeamTagMap(new TeamTagMap().addTagToTeam("ABCD", 0)).withStatusMessage("foo").build(); MatcherAssert.assertThat(objectMapper.writeValueAsString(snapshot), SameJSONAs.sameJSONAs( "{\"snapshotTime\":0,statusMessage:foo,\"startTime\":0,\"endTime\":0,\"teamTagMap\":{\"0\":[\"ABCD\"]}," + "\"teamStates\":{\"0\":{\"lastTagSeenEvent\":{\"type\":\"TagSeen\",\"time\":1000," + "\"tag\":\"ABCD\",\"readerId\":0}, \"tagFragmentCount\":3}}}") .allowingExtraUnexpectedFields()); }
From source file:org.jboss.pnc.buildagent.server.TestGetRunningProcesses.java
@Test public void getRunningProcesses() throws Exception { String terminalUrl = "http://" + HOST + ":" + PORT; HttpURLConnection connection = retrieveProcessList(); Assert.assertEquals(connection.getResponseMessage(), 200, connection.getResponseCode()); JsonNode node = readResponse(connection); Assert.assertEquals(0, node.size()); String context = this.getClass().getName() + ".getRunningProcesses"; ObjectWrapper<Boolean> resultReceived = new ObjectWrapper<>(false); Consumer<TaskStatusUpdateEvent> onStatusUpdate = (statusUpdateEvent) -> { if (statusUpdateEvent.getNewStatus().equals(Status.RUNNING)) { try { HttpURLConnection afterExecution = retrieveProcessList(); Assert.assertEquals(afterExecution.getResponseMessage(), 200, afterExecution.getResponseCode()); JsonNode nodeAfterExecution = readResponse(afterExecution); Assert.assertEquals(1, nodeAfterExecution.size()); resultReceived.set(true); } catch (Exception e) { throw new RuntimeException(e); }/*from w w w.j av a2 s . c o m*/ } }; BuildAgentClient buildAgentClient = new BuildAgentClient(terminalUrl, Optional.empty(), onStatusUpdate, context); buildAgentClient.executeCommand(TEST_COMMAND); Supplier<Boolean> evaluationSupplier = () -> resultReceived.get(); Wait.forCondition(evaluationSupplier, 10, ChronoUnit.SECONDS, "Client was not connected within given timeout."); buildAgentClient.close(); }
From source file:org.darkware.wpman.agents.CronEvent.java
/** * Checks to see if a given {@code CronEvent} is reasonably close to this event. Presumably * this would be used to decide if the other event could piggyback onto the same execution action. * * @param check The {@code CronEvent} to check against. * @return {@code true} if the event is from the same blog and is reasonably close to the same * execution time, otherwise {@code false}. *//*from w w w. j a va2s . co m*/ public boolean reasonablyCloseTo(final CronEvent check) { // Check the blog if (!this.blog.equals(check.blog)) return false; // Check the time if (Math.abs((check.execTime.until(this.execTime, ChronoUnit.SECONDS))) > 15) return false; return true; }
From source file:devbury.dewey.plugins.RemindMe.java
private Date notifyAt(long amount, String units) { ChronoUnit chronoUnit = ChronoUnit.SECONDS; switch (units) { case "weeks": case "week": chronoUnit = ChronoUnit.WEEKS; break;/*from w w w.j av a 2 s . co m*/ case "months": case "month": chronoUnit = ChronoUnit.MONTHS; break; case "days": case "day": chronoUnit = ChronoUnit.DAYS; break; case "hours": case "hour": chronoUnit = ChronoUnit.HOURS; break; case "minutes": case "minute": chronoUnit = ChronoUnit.MINUTES; break; } return Date.from(Instant.now().plus(amount, chronoUnit)); }
From source file:com.querydsl.webhooks.GithubReviewWindow.java
@VisibleForTesting protected static String makeHumanReadable(Duration duration) { StringBuilder output = new StringBuilder(); duration = truncateAndAppend(duration, duration.toDays(), ChronoUnit.DAYS, "day", output); duration = truncateAndAppend(duration, duration.toHours(), ChronoUnit.HOURS, "hour", output); duration = truncateAndAppend(duration, duration.toMinutes(), ChronoUnit.MINUTES, "minute", output); duration = truncateAndAppend(duration, duration.getSeconds(), ChronoUnit.SECONDS, "second", output); return output.toString().trim(); }