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

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

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

Duration.plusSeconds介绍

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

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

代码示例

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

return Duration.ofHours(hours)
    .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

.plusHours(interval.getHours())
      .plusMinutes(interval.getMinutes())
      .plusSeconds(secondsLong)
      .plusNanos(nanos);
});

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

@Test
public void createSessionWhenCustomMaxInactiveIntervalThenCustomMaxInactiveInterval() {
  final Duration expectedMaxInterval = new MapSession().getMaxInactiveInterval()
      .plusSeconds(10);
  this.repository.setDefaultMaxInactiveInterval(
      (int) expectedMaxInterval.getSeconds());
  Session session = this.repository.createSession().block();
  assertThat(session.getMaxInactiveInterval())
      .isEqualTo(expectedMaxInterval);
}

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

@Test
public void createSessionCustomDefaultExpiration() {
  final Duration expectedMaxInterval = new MapSession().getMaxInactiveInterval()
      .plusSeconds(10);
  this.repository.setDefaultMaxInactiveInterval(
      (int) expectedMaxInterval.getSeconds());
  Session session = this.repository.createSession();
  assertThat(session.getMaxInactiveInterval())
      .isEqualTo(expectedMaxInterval);
}

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

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

代码示例来源:origin: palantir/atlasdb

private Duration getBackoffTimeWhenSweepHasNotRun() {
  return Duration.ofMillis(sweepPauseMillis.get()).plusSeconds(1).multipliedBy(20); // 2 minutes by default
}

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

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

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Returns a {@link java.time.Duration} that is one second longer than this duration.
 *
 * @param self a Duration
 * @return a Duration
 * @since 2.5.0
 */
public static Duration next(final Duration self) {
  return self.plusSeconds(1);
}

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Returns a {@link java.time.Duration} that is {@code seconds} seconds longer than this duration.
 *
 * @param self    a Duration
 * @param seconds the number of seconds to add
 * @return a Duration
 * @since 2.5.0
 */
public static Duration plus(final Duration self, long seconds) {
  return self.plusSeconds(seconds);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this duration with the specified duration in seconds subtracted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param secondsToSubtract  the seconds to subtract, positive or negative
 * @return a {@code Duration} based on this duration with the specified seconds subtracted, not null
 * @throws ArithmeticException if numeric overflow occurs
 */
public Duration minusSeconds(long secondsToSubtract) {
  return (secondsToSubtract == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-secondsToSubtract));
}

代码示例来源:origin: stackoverflow.com

import static java.lang.Integer.valueOf;

import java.time.Duration;

public class DurationParser {
  public static Duration parse(String input) {
    int colonIndex = input.indexOf(':');
    String mm = input.substring(0, colonIndex);
    String ss = input.substring(colonIndex + 1);
    return Duration.ofMinutes(valueOf(mm)).plusSeconds(valueOf(ss));
  }
}

代码示例来源:origin: io.digdag/digdag-core

@Override
  public Instant calculateTime(Instant time, ZoneId timeZone)
  {
    Duration duration = Duration.ofHours(hour).plusMinutes(minute).plusSeconds(second);
    Instant deadline = time.plus(duration);
    return deadline;
  }
}

代码示例来源: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: 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));
}

相关文章