java.time.Duration.ofDays()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(431)

本文整理了Java中java.time.Duration.ofDays()方法的一些代码示例,展示了Duration.ofDays()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.ofDays()方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:ofDays

Duration.ofDays介绍

[英]Obtains an instance of Duration from a number of standard 24 hour days.

The seconds are calculated based on the standard definition of a day, where each day is 86400 seconds which implies a 24 hour day. The nanosecond in second field is set to zero.
[中]从标准的24小时天数中获取持续时间实例。
秒数是根据一天的标准定义计算的,其中每天为86400秒,即一天24小时。第二个字段中的纳秒设置为零。

代码示例

代码示例来源:origin: apache/flink

@Override
public void run(SourceContext<Email> ctx) throws Exception {
  // Sleep for 10 seconds on start to allow time to copy jobid
  Thread.sleep(10000L);
  int types = LabelSurrogate.Type.values().length;
  while (isRunning) {
    int r = random.nextInt(100);
    final EmailId emailId = new EmailId(Integer.toString(random.nextInt()));
    final Instant timestamp = Instant.now().minus(Duration.ofDays(1L));
    final String foo = String.format("foo #%d", r);
    final LabelSurrogate label = new LabelSurrogate(LabelSurrogate.Type.values()[r % types], "bar");
    synchronized (ctx.getCheckpointLock()) {
      ctx.collect(new Email(emailId, timestamp, foo, label));
    }
    Thread.sleep(30L);
  }
}

代码示例来源:origin: spring-projects/spring-security

public static OAuth2AccessToken scopes(String... scopes) {
    return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER,
        "scopes",
        Instant.now(),
        Instant.now().plus(Duration.ofDays(1)),
        new HashSet<>(Arrays.asList(scopes)));
  }
}

代码示例来源:origin: spring-projects/spring-security

public static OAuth2AccessToken noScopes() {
  return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER,
      "no-scopes",
      Instant.now(),
      Instant.now().plus(Duration.ofDays(1)));
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void build_filled() {
 Timeouts t = TimeoutsBuilder.timeouts()
  .read(Duration.ofDays(1))
  .write(Duration.ofDays(2))
  .connection(Duration.ofDays(3))
  .build();
 assertThat(t.getReadOperationTimeout()).isEqualTo(Duration.ofDays(1));
 assertThat(t.getWriteOperationTimeout()).isEqualTo(Duration.ofDays(2));
 assertThat(t.getConnectionTimeout()).isEqualTo(Duration.ofDays(3));
}

代码示例来源:origin: google/guava

@GwtIncompatible // java.time.Duration
public void testLargeDurations() {
 java.time.Duration threeHundredYears = java.time.Duration.ofDays(365 * 300);
 CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
 try {
  builder.expireAfterWrite(threeHundredYears);
  fail();
 } catch (ArithmeticException expected) {
 }
 try {
  builder.expireAfterAccess(threeHundredYears);
  fail();
 } catch (ArithmeticException expected) {
 }
 try {
  builder.refreshAfterWrite(threeHundredYears);
  fail();
 } catch (ArithmeticException expected) {
 }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid()
{
  testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 3, Duration.ofSeconds( 5 ) );
  testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 1, Duration.ofSeconds( 11 ) );
  testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 22, Duration.ofMinutes( 2 ) );
  testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 42, Duration.ofDays( 4 ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldFailWhenDurationIsSentWithRun() throws Exception
{
  testFailureWithV2Value( ValueUtils.of( Duration.ofDays( 10 ) ), "Duration" );
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeOnSubscribe() {
  StepVerifier.withVirtualTime(() -> Mono.delay(Duration.ofDays(2))
                      .map(l -> "foo"))
        .thenAwait(Duration.ofDays(3))
        .expectNext("foo")
        .expectComplete()
        .verify();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeOnError() {
  StepVerifier.withVirtualTime(() -> Mono.never()
                      .timeout(Duration.ofDays(2))
                      .map(l -> "foo"))
        .thenAwait(Duration.ofDays(2))
        .expectError(TimeoutException.class)
        .verify();
}

代码示例来源:origin: reactor/reactor-core

@Test(expected = IllegalArgumentException.class)
public void failTime(){
  Flux.never()
    .replay( Duration.ofDays(-1));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void maxAge() {
  Duration maxAge = Duration.ofDays(365);
  String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis());
  expires = expires.substring(0, expires.indexOf(":") + 1);
  assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf(
      startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires),
      endsWith(" GMT")));
  assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf(
      startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires),
      endsWith(" GMT")));
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testWriteReadNegativeDuration() {
  handle.execute("insert into intervals(id, foo) values(?, ?)",
      8, Duration.ofDays(-3).plusMinutes(2));
  final Duration d = handle.createQuery("select foo from intervals where id=?")
      .bind(0, 8)
      .mapTo(Duration.class)
      .findOnly();
  assertThat(d).isEqualTo(Duration.ofDays(-3).plusMinutes(2));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeNoEvent() {
  StepVerifier.withVirtualTime(() -> Mono.just("foo")
                      .delaySubscription(Duration.ofDays(2)))
        .expectSubscription()
        .expectNoEvent(Duration.ofDays(2))
        .expectNext("foo")
        .expectComplete()
        .verify();
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldCallExternalErrorOnDuration() throws Exception
{
  assumeThat( packerUnderTest.version(), equalTo( 1L ) );
  testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), durationValue( Duration.ofDays( 10 ) ),
      "Duration values cannot be unpacked with this version of bolt." );
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeNoEventError() {
  assertThatExceptionOfType(AssertionError.class)
      .isThrownBy(() -> StepVerifier.withVirtualTime(() -> Mono.just("foo")
                      .delaySubscription(Duration.ofDays(2)))
        .expectSubscription()
        .expectNoEvent(Duration.ofDays(2))
        .expectNext("foo")
        .expectNoEvent(Duration.ofDays(2))
        .expectComplete()
        .verify())
      .withMessage("Unexpected completion during a no-event expectation");
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testReadNegativeDuration() {
  handle.execute("insert into intervals(id, foo) values(?, interval '-2 days -3 hours')", 7);
  final Duration d = handle.createQuery("select foo from intervals where id=?")
      .bind(0, 7)
      .mapTo(Duration.class)
      .findOnly();
  assertThat(d).isEqualTo(Duration.ofDays(-2).plusHours(-3));
}

代码示例来源:origin: Netflix/concurrency-limits

@Test(expected = IllegalArgumentException.class)
  public void failOnHighTimeout() {
    SettableLimit limit = SettableLimit.startingAt(1);
    BlockingLimiter<Void> limiter = BlockingLimiter.wrap(SimpleLimiter.newBuilder().limit(limit).build(), Duration.ofDays(1));
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeNoEventNever() {
  StepVerifier.withVirtualTime(() -> Mono.never()
                      .log())
        .expectSubscription()
        .expectNoEvent(Duration.ofDays(10000))
        .thenCancel()
        .verify();
}

代码示例来源:origin: debezium/debezium

@Test
public void shouldAlwaysCommit() {
  OffsetCommitPolicy policy = OffsetCommitPolicy.always();
  assertThat(policy.performCommit(0, Duration.ofNanos(0))).isTrue();
  assertThat(policy.performCommit(10000, Duration.ofDays(1000))).isTrue();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void verifyVirtualTimeNoEventNeverError() {
  assertThatExceptionOfType(AssertionError.class)
      .isThrownBy(() -> StepVerifier.withVirtualTime(() -> Mono.never()
                                   .log())
                     .expectNoEvent(Duration.ofDays(10000))
                     .thenCancel()
                     .verify())
      .withMessageStartingWith("expectation failed (expected no event: onSubscribe(");
}

相关文章