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

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

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

Duration.plusHours介绍

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

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

代码示例

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

final long nanos = (long) ((seconds - secondsLong) * 1e9);
return Duration.ofDays(interval.getDays())
    .plusHours(interval.getHours())
    .plusMinutes(interval.getMinutes())
    .plusSeconds(secondsLong)

代码示例来源: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: 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: com.github.seratch/java-time-backport

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

代码示例来源:origin: org.nuxeo.common/nuxeo-common

millis = Long.parseLong(matcher.group(5));
return Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusMillis(
    millis);

代码示例来源:origin: yescallop/EssentialsNK

public boolean mute(Player player, int d, int h, int m, int s) {
  return this.mute(player, Duration.ZERO.plusDays(d).plusHours(h).plusMinutes(m).plusSeconds(s));
}

代码示例来源:origin: yescallop/EssentialsNK

public String getMuteTimeMessage(int d, int h, int m, int s) {
  return getDurationString(Duration.ZERO.plusDays(d).plusHours(h).plusMinutes(m).plusSeconds(s));
}

代码示例来源:origin: org.jdbi/jdbi3-postgres

final long nanos = (long) ((seconds - secondsLong) * 1e9);
return Duration.ofDays(interval.getDays())
    .plusHours(interval.getHours())
    .plusMinutes(interval.getMinutes())
    .plusSeconds(secondsLong)

代码示例来源:origin: yescallop/EssentialsNK

break;
case '时':
  unit = unit.plusHours(1);
  break;
case '分':

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

for (Duration duration = Duration.ofSeconds(0).plusNanos(0);
    duration.compareTo(Duration.ofDays(1000)) <= 0;
    duration = duration.plusHours(1)) {
  String textDuration = convertStringFromDuration(duration, settings);
  Duration durationParsed = convertStringToDuration(textDuration, settings);

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

代码示例来源: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.mnode.ical4j/ical4j

public static TemporalAmountAdapter from(Dur dur) {
  TemporalAmount duration;
  if (dur.getWeeks() > 0) {
    Period p = Period.ofWeeks(dur.getWeeks());
    if (dur.isNegative()) {
      p = p.negated();
    }
    duration = p;
  } else {
    Duration d = Duration.ofDays(dur.getDays())
        .plusHours(dur.getHours())
        .plusMinutes(dur.getMinutes())
        .plusSeconds(dur.getSeconds());
    if (dur.isNegative()) {
      d = d.negated();
    }
    duration = d;
  }
  return new TemporalAmountAdapter(duration);
}

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

public static TemporalAmountAdapter from(Dur dur) {
  TemporalAmount duration;
  if (dur.getWeeks() > 0) {
    Period p = Period.ofWeeks(dur.getWeeks());
    if (dur.isNegative()) {
      p = p.negated();
    }
    duration = p;
  } else {
    Duration d = Duration.ofDays(dur.getDays())
        .plusHours(dur.getHours())
        .plusMinutes(dur.getMinutes())
        .plusSeconds(dur.getSeconds());
    if (dur.isNegative()) {
      d = d.negated();
    }
    duration = d;
  }
  return new TemporalAmountAdapter(duration);
}

代码示例来源:origin: com.github.marschall/threeten-jpa-oracle-impl

/**
 * Converts {@link INTERVALDS} to {@link Duration}.
 *
 * @param dbData the data from the database to be converted, possibly {@code null}
 * @return the converted value, possibly {@code null}
 */
public static Duration intervaldsToDuration(INTERVALDS dbData) {
 if (dbData == null) {
  return null;
 }
 byte[] bytes = dbData.toBytes();
 int day = toUnsignedInt(bytes[0]) << 24
     | toUnsignedInt(bytes[1]) << 16
     | toUnsignedInt(bytes[2]) << 8
     | toUnsignedInt(bytes[3]);
 day ^= HIGH_BIT_FLAG;
 int hour = toUnsignedInt(bytes[4]) - 60;
 int minute = toUnsignedInt(bytes[5]) - 60;
 int second = toUnsignedInt(bytes[6]) - 60;
 int nano = toUnsignedInt(bytes[7]) << 24
     | toUnsignedInt(bytes[8]) << 16
     | toUnsignedInt(bytes[9]) << 8
     | toUnsignedInt(bytes[10]);
 nano ^= HIGH_BIT_FLAG;
 return Duration.ofDays(day)
     .plusHours(hour)
     .plusMinutes(minute)
     .plusSeconds(second)
     .plusNanos(nano);
}

代码示例来源:origin: marschall/threeten-jpa

/**
 * Converts {@link INTERVALDS} to {@link Duration}.
 *
 * @param dbData the data from the database to be converted, possibly {@code null}
 * @return the converted value, possibly {@code null}
 */
public static Duration intervaldsToDuration(INTERVALDS dbData) {
 if (dbData == null) {
  return null;
 }
 byte[] bytes = dbData.toBytes();
 int day = toUnsignedInt(bytes[0]) << 24
     | toUnsignedInt(bytes[1]) << 16
     | toUnsignedInt(bytes[2]) << 8
     | toUnsignedInt(bytes[3]);
 day ^= HIGH_BIT_FLAG;
 int hour = toUnsignedInt(bytes[4]) - 60;
 int minute = toUnsignedInt(bytes[5]) - 60;
 int second = toUnsignedInt(bytes[6]) - 60;
 int nano = toUnsignedInt(bytes[7]) << 24
     | toUnsignedInt(bytes[8]) << 16
     | toUnsignedInt(bytes[9]) << 8
     | toUnsignedInt(bytes[10]);
 nano ^= HIGH_BIT_FLAG;
 return Duration.ofDays(day)
     .plusHours(hour)
     .plusMinutes(minute)
     .plusSeconds(second)
     .plusNanos(nano);
}

相关文章