本文整理了Java中java.time.Duration.minus()
方法的一些代码示例,展示了Duration.minus()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.minus()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:minus
[英]Returns a copy of this duration with the specified duration subtracted.
The duration amount is measured in terms of the specified unit. Only a subset of units are accepted by this method. The unit must either have an TemporalUnit#isDurationEstimated() or be ChronoUnit#DAYS which is treated as 24 hours. Other units throw an exception.
This instance is immutable and unaffected by this method call.
[中]返回此持续时间的副本,并减去指定的持续时间。
持续时间金额按指定单位计量。此方法仅接受单元的子集。该装置必须有一个临时单位“isDurationEstimated()”或一个计时单位“DAYS”,即24小时。其他单位抛出异常。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: thinkaurelius/titan
private Duration maxWaitTime() {
if (!toSend.isEmpty()) {
return maxSendDelay.minus(timeSinceFirstMsg());
}
return FOREVER;
}
代码示例来源:origin: JanusGraph/janusgraph
private Duration maxWaitTime() {
if (!toSend.isEmpty()) {
return maxSendDelay.minus(timeSinceFirstMsg());
}
return FOREVER;
}
代码示例来源:origin: debezium/debezium
@Override
public Duration remaining() {
return time.minus(start.elapsedTime(), ChronoUnit.MILLIS);
}
};
代码示例来源:origin: runelite/runelite
@Override
public boolean render()
{
final boolean rendered = super.render();
if (rendered)
{
final Duration fromStart = Duration.between(getStartTime(), Instant.now());
return !fromStart.minus(timer.getInitialDelay()).isNegative();
}
return false;
}
代码示例来源:origin: reactor/reactor-core
jitterOffset = Math.round(Long.MAX_VALUE * jitterFactor);
long lowBound = Math.max(firstBackoff.minus(nextBackoff)
.toMillis(), -jitterOffset);
long highBound = Math.min(maxBackoff.minus(nextBackoff)
.toMillis(), jitterOffset);
代码示例来源:origin: thinkaurelius/titan
@Override
public void lock(Duration timeout) {
Timer t = times.getTimer().start();
first.lock(timeout);
Duration remainingTimeout = timeout.minus(t.elapsed());
try {
second.lock(remainingTimeout);
} catch (RuntimeException e) {
first.unlock();
throw e;
}
}
代码示例来源:origin: JanusGraph/janusgraph
@Override
public void lock(Duration timeout) {
Timer t = times.getTimer().start();
first.lock(timeout);
Duration remainingTimeout = timeout.minus(t.elapsed());
try {
second.lock(remainingTimeout);
} catch (RuntimeException e) {
first.unlock();
throw e;
}
}
代码示例来源:origin: runelite/runelite
private void resetInfobox()
{
if (deathTimer != null)
{
infoBoxManager.removeInfoBox(deathTimer);
deathTimer = null;
}
if (hasDied() && config.showDeathInfoBox())
{
Instant now = Instant.now();
Duration timeLeft = Duration.ofHours(1).minus(Duration.between(config.timeOfDeath(), now));
if (!timeLeft.isNegative() && !timeLeft.isZero())
{
deathTimer = new Timer(timeLeft.getSeconds(), ChronoUnit.SECONDS, getBonesImage(), this);
deathTimer.setTooltip("Died on world: " + config.deathWorld());
infoBoxManager.addInfoBox(deathTimer);
}
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyVirtualTimeOnNextInterval() {
Duration r;
r = StepVerifier.withVirtualTime(() -> Flux.interval(Duration.ofSeconds(3))
.map(d -> "t" + d))
.thenAwait(Duration.ofSeconds(3))
.expectNext("t0")
.thenAwait(Duration.ofSeconds(3))
.expectNext("t1")
.thenAwait(Duration.ofSeconds(3))
.expectNext("t2")
.thenCancel()
.verify();
assertThat(r.minus(Duration.ofSeconds(9)).toMillis()).isNegative();
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldGetNanosOfDayUTC()
{
LocalTime localTime = LocalTime.of( 14, 19, 18, 123999 );
ZoneOffset offset = ZoneOffset.ofHours( -12 );
OffsetTime time = OffsetTime.of( localTime, offset );
long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( time );
long expectedNanosOfDayUTC = Duration.ofSeconds( localTime.toSecondOfDay() )
.minus( offset.getTotalSeconds(), SECONDS )
.toNanos();
assertEquals( expectedNanosOfDayUTC + localTime.getNano(), nanosOfDayUTC );
}
}
代码示例来源:origin: reactor/reactor-core
@Override
void run(DefaultVerifySubscriber<T> parent) throws Exception {
if(parent.virtualTimeScheduler != null) {
parent.monitorSignal = true;
virtualOrRealWait(duration.minus(Duration.ofNanos(1)), parent);
parent.monitorSignal = false;
if (parent.terminalError != null && !parent.isCancelled()) {
Throwable terminalError = parent.terminalError.getThrowable();
throw parent.errorFormatter.assertionError("Unexpected error during a no-event expectation: " + terminalError, terminalError);
}
else if (parent.isTerminated() && !parent.isCancelled()) {
throw parent.errorFormatter.assertionError("Unexpected completion during a no-event expectation");
}
virtualOrRealWait(Duration.ofNanos(1), parent);
}
else{
parent.monitorSignal = true;
virtualOrRealWait(duration, parent);
parent.monitorSignal = false;
if (parent.terminalError != null && !parent.isCancelled()) {
Throwable terminalError = parent.terminalError.getThrowable();
throw parent.errorFormatter.assertionError("Unexpected error during a no-event expectation: " + terminalError, terminalError);
}
else if (parent.isTerminated() && !parent.isCancelled()) {
throw parent.errorFormatter.assertionError("Unexpected completion during a no-event expectation");
}
}
}
}
代码示例来源:origin: pravega/pravega
/**
* Calculates the amount of time elapsed since the current iteration started.
*
* @param timer The reference timer.
*/
Duration getElapsedSinceIterationStart(AbstractTimer timer) {
return timer.getElapsed().minus(this.currentIterationStartTime.get());
}
代码示例来源:origin: com.thinkaurelius.titan/titan-core
private Duration maxWaitTime() {
if (!toSend.isEmpty()) {
return maxSendDelay.minus(timeSinceFirstMsg());
}
return FOREVER;
}
代码示例来源:origin: org.eclipse.microprofile.fault-tolerance/microprofile-fault-tolerance-tck
@Override
protected boolean matchesSafely(Duration item, Description mismatchDescription) {
Duration difference = item.minus(target).abs();
mismatchDescription.appendValue(item)
.appendText(" which is ")
.appendValue(difference)
.appendText(" from ")
.appendValue(target);
return difference.compareTo(margin) <= 0; // difference <= margin
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
private TemporalAmount minus(TemporalAmount first, TemporalAmount second) {
if (first instanceof Period && second instanceof Period) {
return ((Period) first).minus(second);
} else if (first instanceof Duration && second instanceof Duration) {
return ((Duration)first).minus((Duration)second);
} else {
throw new DMNRuntimeException(String.format("Cannot subtract '%s' and '%s'", first, second));
}
}
代码示例来源:origin: com.yahoo.vespa/orchestrator
@Override
public Duration getReadTimeoutOrThrow() {
Duration timeLeft = timeBudget.timeLeft().get();
// timeLeft = CONNECT_TIMEOUT + readTimeout
Duration readTimeout = timeLeft.minus(CONNECT_TIMEOUT);
if (readTimeout.toMillis() <= 0) {
throw new UncheckedTimeoutException("Timed out after " + timeBudget.originalTimeout().get());
}
return readTimeout;
}
代码示例来源:origin: org.springframework.session/spring-session-data-geode
@Override @SuppressWarnings("all")
public Optional<Duration> determineExpirationTimeout(@NonNull Session session) {
return getIdleTimeout()
.map(idleTimeout -> idleTimeout.minus(computeIdleTime(session)));
}
代码示例来源:origin: org.springframework.session/spring-session-data-geode
@Override
public Optional<Duration> determineExpirationTimeout(@NonNull Session session) {
Optional<Duration> idleTimeout = super.determineExpirationTimeout(session);
Duration fixedExpirationTimeout = getFixedTimeout().minus(computeTimeSinceCreation(session));
return idleTimeout.filter(it -> it.compareTo(fixedExpirationTimeout) <= 0).isPresent()
? Optional.empty() : Optional.of(fixedExpirationTimeout);
}
代码示例来源:origin: com.thinkaurelius.titan/titan-core
@Override
public void lock(Duration timeout) {
Timer t = times.getTimer().start();
first.lock(timeout);
Duration remainingTimeout = timeout.minus(t.elapsed());
try {
second.lock(remainingTimeout);
} catch (RuntimeException e) {
first.unlock();
throw e;
}
}
代码示例来源:origin: Wikia/selenium-tests
private void simulateUserActivity(Duration duration, Duration waitDuration) {
while (!duration.isNegative()) {
jsActions.scrollBy(0, 100);
wait.forX(waitDuration);
jsActions.scrollBy(0, -100);
duration = duration.minus(waitDuration);
}
}
内容来源于网络,如有侵权,请联系作者删除!