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

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

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

Duration.plusMinutes介绍

[英]Returns a copy of this duration with the specified duration in minutes added.

This instance is immutable and unaffected by this method call.
[中]返回此持续时间的副本,并添加指定的持续时间(以分钟为单位)。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

.plusMinutes(minutes)
.plusSeconds(seconds)
.plusNanos(nanoSeconds);

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

/**
 * Converts a MySQL {@code TIME} value <em>without fractional seconds</em> to a {@link java.time.Duration}.
 *
 * @param inputStream the binary stream containing the raw binlog event data for the value
 * @return the {@link LocalTime} object
 * @throws IOException if there is an error reading from the binlog event data
 */
protected static Serializable deserializeTime(ByteArrayInputStream inputStream) throws IOException {
  // Times are stored as an integer as `HHMMSS`, so we need to split out the digits ...
  int value = inputStream.readInteger(3);
  int[] split = split(value, 100, 3);
  int hours = split[2];
  int minutes = split[1];
  int seconds = split[0];
  return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds);
}

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

return Duration.ofDays(interval.getDays())
    .plusHours(interval.getHours())
    .plusMinutes(interval.getMinutes())
    .plusSeconds(secondsLong)
    .plusNanos(nanos);

代码示例来源: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: spring-projects/spring-session

@Test
public void onExpirationUpdatedSetExpireSession() throws Exception {
  String sessionKey = this.policy.getSessionKey(this.session.getId());
  this.policy.onExpirationUpdated(null, this.session);
  verify(this.sessionRedisOperations).boundHashOps(sessionKey);
  verify(this.hashOperations).expire(
      this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(),
      TimeUnit.SECONDS);
}

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

@Test
public void onExpirationUpdatedAddsExpirationTimeRoundedUp() throws Exception {
  long expirationTimeInMs = RedisSessionExpirationPolicy
      .expiresInMillis(this.session);
  long expirationRoundedUpInMs = RedisSessionExpirationPolicy
      .roundUpToNextMinute(expirationTimeInMs);
  String expectedExpireKey = this.policy.getExpirationKey(expirationRoundedUpInMs);
  this.policy.onExpirationUpdated(null, this.session);
  verify(this.sessionRedisOperations).boundSetOps(expectedExpireKey);
  verify(this.setOperations).add("expires:" + this.session.getId());
  verify(this.setOperations).expire(
      this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(),
      TimeUnit.SECONDS);
}

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

@Test
public void onExpirationUpdatedDeleteOnZero() throws Exception {
  String sessionKey = this.policy.getSessionKey("expires:" + this.session.getId());
  long originalExpirationTimeInMs = ONE_MINUTE_AGO;
  this.session.setMaxInactiveInterval(Duration.ZERO);
  this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session);
  // verify the original is removed
  verify(this.setOperations).remove("expires:" + this.session.getId());
  verify(this.setOperations).add("expires:" + this.session.getId());
  verify(this.sessionRedisOperations).delete(sessionKey);
  verify(this.setOperations).expire(
      this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(),
      TimeUnit.SECONDS);
}

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

@Test
public void testReadsViaFluentAPI() {
  List<Duration> periods = handle.createQuery("select foo from intervals where id = 1 or id = 2 order by id")
      .mapTo(Duration.class)
      .list();
  assertThat(periods).isEqualTo(ImmutableList.of(
      Duration.ofDays(1).plusHours(15),
      Duration.ofDays(40).plusMinutes(22)
  ));
}

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

nanoSeconds = deserializeFractionalSecondsInNanos(meta, inputStream);
return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusNanos(nanoSeconds);

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

@Test
public void saveJavadocSummary() {
  RedisSession session = this.redisRepository.createSession();
  String sessionKey = "spring:session:sessions:" + session.getId();
  String backgroundExpireKey = "spring:session:expirations:"
      + RedisSessionExpirationPolicy.roundUpToNextMinute(
          RedisSessionExpirationPolicy.expiresInMillis(session));
  String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId();
  given(this.redisOperations.boundHashOps(sessionKey))
      .willReturn(this.boundHashOperations);
  given(this.redisOperations.boundSetOps(backgroundExpireKey))
      .willReturn(this.boundSetOperations);
  given(this.redisOperations.boundValueOps(destroyedTriggerKey))
      .willReturn(this.boundValueOperations);
  this.redisRepository.save(session);
  // the actual data in the session expires 5 minutes after expiration so the data
  // can be accessed in expiration events
  // if the session is retrieved and expired it will not be returned since
  // findById checks if it is expired
  long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5)
      .getSeconds();
  verify(this.boundHashOperations).expire(fiveMinutesAfterExpires,
      TimeUnit.SECONDS);
  verify(this.boundSetOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
  verify(this.boundSetOperations).add("expires:" + session.getId());
  verify(this.boundValueOperations).expire(1800L, TimeUnit.SECONDS);
  verify(this.boundValueOperations).append("");
}

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

@Test
public void saveJavadoc() {
  RedisSession session = this.redisRepository.new RedisSession(this.cached);
  session.setLastAccessedTime(session.getLastAccessedTime());
  given(this.redisOperations.boundHashOps("spring:session:sessions:session-id"))
      .willReturn(this.boundHashOperations);
  given(this.redisOperations
      .boundSetOps("spring:session:expirations:1404361860000"))
          .willReturn(this.boundSetOperations);
  given(this.redisOperations
      .boundValueOps("spring:session:sessions:expires:session-id"))
          .willReturn(this.boundValueOperations);
  this.redisRepository.save(session);
  // the actual data in the session expires 5 minutes after expiration so the data
  // can be accessed in expiration events
  // if the session is retrieved and expired it will not be returned since
  // findById checks if it is expired
  verify(this.boundHashOperations).expire(
      session.getMaxInactiveInterval().plusMinutes(5).getSeconds(),
      TimeUnit.SECONDS);
}

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

long expectedMillis = Duration.ofHours(17).plusMinutes(51).plusSeconds(4).plusMillis(780).toMillis();
assertThat(c2).isEqualTo((int)expectedMillis);

代码示例来源:origin: reactiverse/reactive-pg-client

private static void binaryEncodeINTERVAL(Interval interval, ByteBuf buff) {
 Duration duration = Duration
  .ofHours(interval.getHours())
  .plusMinutes(interval.getMinutes())
  .plusSeconds(interval.getSeconds())
  .plus(interval.getMicroseconds(), ChronoUnit.MICROS);
 // days won't be changed
 Period monthYear = Period.of(interval.getYears(), interval.getMonths(), interval.getDays()).normalized();
 binaryEncodeINT8(NANOSECONDS.toMicros(duration.toNanos()), buff);
 binaryEncodeINT4(monthYear.getDays(), buff);
 binaryEncodeINT4((int) monthYear.toTotalMonths(), buff);
}

代码示例来源:origin: io.reactiverse/reactive-pg-client

private static void binaryEncodeINTERVAL(Interval interval, ByteBuf buff) {
 Duration duration = Duration
  .ofHours(interval.getHours())
  .plusMinutes(interval.getMinutes())
  .plusSeconds(interval.getSeconds())
  .plus(interval.getMicroseconds(), ChronoUnit.MICROS);
 // days won't be changed
 Period monthYear = Period.of(interval.getYears(), interval.getMonths(), interval.getDays()).normalized();
 binaryEncodeINT8(NANOSECONDS.toMicros(duration.toNanos()), buff);
 binaryEncodeINT4(monthYear.getDays(), buff);
 binaryEncodeINT4((int) monthYear.toTotalMonths(), buff);
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

@Override
public void initialize(DurationMin constraintAnnotation) {
  this.minDuration = Duration.ofNanos( constraintAnnotation.nanos() )
      .plusMillis( constraintAnnotation.millis() )
      .plusSeconds( constraintAnnotation.seconds() )
      .plusMinutes( constraintAnnotation.minutes() )
      .plusHours( constraintAnnotation.hours() )
      .plusDays( constraintAnnotation.days() );
  this.inclusive = constraintAnnotation.inclusive();
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

@Override
public void initialize(DurationMax constraintAnnotation) {
  this.maxDuration = Duration.ofNanos( constraintAnnotation.nanos() )
      .plusMillis( constraintAnnotation.millis() )
      .plusSeconds( constraintAnnotation.seconds() )
      .plusMinutes( constraintAnnotation.minutes() )
      .plusHours( constraintAnnotation.hours() )
      .plusDays( constraintAnnotation.days() );
  this.inclusive = constraintAnnotation.inclusive();
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

protected TemporalAmount toTemporalDuration(Duration duration) {
  int days = normalize(duration.getDays());
  int hours = normalize(duration.getHours());
  int minutes = normalize(duration.getMinutes());
  int seconds = normalize(duration.getSeconds());
  java.time.Duration timeDuration = java.time.Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds);
  return duration.getSign() == -1 ? timeDuration.negated() : timeDuration;
}

代码示例来源:origin: goldmansachs/jdmn

protected TemporalAmount toTemporalDuration(Duration duration) {
  int days = normalize(duration.getDays());
  int hours = normalize(duration.getHours());
  int minutes = normalize(duration.getMinutes());
  int seconds = normalize(duration.getSeconds());
  java.time.Duration timeDuration = java.time.Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds);
  return duration.getSign() == -1 ? timeDuration.negated() : timeDuration;
}

代码示例来源:origin: org.kie/kie-dmn-feel

@Test
public void invokeParamTemporalDuration() {
  FunctionTestUtil.assertResult(
      durationFunction.invoke(Duration.parse("P2DT3H28M15S")),
      Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28).plusSeconds(15));
}

代码示例来源:origin: org.kie/kie-dmn-feel

@Test
public void invokeParamStringDuration() {
  FunctionTestUtil.assertResult(durationFunction.invoke("P2D"), Duration.of(2, ChronoUnit.DAYS));
  FunctionTestUtil.assertResult(durationFunction.invoke("P2DT3H"), Duration.of(2, ChronoUnit.DAYS).plusHours(3));
  FunctionTestUtil.assertResult(
      durationFunction.invoke("P2DT3H28M"),
      Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28));
  FunctionTestUtil.assertResult(
      durationFunction.invoke("P2DT3H28M15S"),
      Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28).plusSeconds(15));
}

相关文章