本文整理了Java中java.time.OffsetDateTime.minus()
方法的一些代码示例,展示了OffsetDateTime.minus()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.minus()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:minus
[英]Returns a copy of this date-time with the specified period subtracted.
This method returns a new date-time based on this date-time with the specified period subtracted. This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days. The unit is responsible for the details of the calculation, including the resolution of any edge cases in the calculation. The offset is not part of the calculation and will be unchanged in the result.
This instance is immutable and unaffected by this method call.
[中]返回此日期时间的副本,并减去指定的期间。
此方法基于此日期时间返回一个新的日期时间,并减去指定的期间。这可以用来减去单位定义的任何期间,例如减去年、月或日。该部门负责计算的细节,包括计算中任何边缘情况的解决方案。偏移量不是计算的一部分,在结果中将保持不变。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: SonarSource/sonarqube
private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
Date actualCreatedAfter = createdAfter;
if (createdInLast != null) {
actualCreatedAfter = Date.from(
OffsetDateTime.now(clock)
.minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
.toInstant());
}
builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
}
代码示例来源:origin: kiegroup/jbpm
startAtDelayDur = Duration.between(OffsetDateTime.now(), endTime.minus(period));
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
Date actualCreatedAfter = createdAfter;
if (createdInLast != null) {
actualCreatedAfter = Date.from(
OffsetDateTime.now(clock)
.minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
.toInstant());
}
builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
}
代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene
private OffsetDateTime next(OffsetDateTime from, boolean forward) {
OffsetDateTime to;
if (forward) {
to = this._intervalDate == null ? from : from.plus(this._intervalDate);
to = this._intervalTime == null ? to : to.plus(this._intervalTime);
if (this._end != null && to.isAfter(this._end)) to = this._end;
} else {
to = this._intervalDate == null ? from : from.minus(this._intervalDate);
to = this._intervalTime == null ? to : to.minus(this._intervalTime);
if (this._end != null && to.isBefore(this._start)) to = this._start;
}
return to;
}
代码示例来源:origin: org.n52.wps/engine
@Override
public void run() {
list(basePath).filter(shouldBeDeleted(OffsetDateTime.now().minus(duration))).forEach(this::delete);
}
代码示例来源:origin: zolyfarkas/spf4j
String strNrDays = validatorConfigs.get("maxNrOfDaysBackCheckForCompatibility");
if (strNrDays == null) {
instantToGoBack = Instant.now().atOffset(ZoneOffset.UTC).minus(1, ChronoUnit.YEARS).toInstant();
} else {
instantToGoBack = Instant.now().atOffset(ZoneOffset.UTC)
.minus(Integer.parseInt(strNrDays), ChronoUnit.DAYS).toInstant();
代码示例来源:origin: net.aholbrook.paseto/core
@Override
public void check(Token token, VerificationContext context) {
OffsetDateTime time = this.time == null ? OffsetDateTime.now(Clock.systemUTC()) : this.time;
if (token.getIssuedAt() == null) {
throw new MissingClaimException(Token.CLAIM_ISSUED_AT, NAME, token);
}
if (token.getIssuedAt().minus(allowableDrift).isAfter(time)) {
throw new IssuedInFutureException(time, token.getIssuedAt(), NAME, token);
}
}
}
代码示例来源:origin: org.kie/kie-dmn-feel
return ((ZonedDateTime) left).minus( (Period) right);
} else if ( left instanceof OffsetDateTime && right instanceof Period ) {
return ((OffsetDateTime) left).minus( (Period) right);
} else if ( left instanceof LocalDateTime && right instanceof Period ) {
return ((LocalDateTime) left).minus( (Period) right);
return ((ZonedDateTime) left).minus( (Duration) right);
} else if ( left instanceof OffsetDateTime && right instanceof Duration ) {
return ((OffsetDateTime) left).minus( (Duration) right);
} else if ( left instanceof LocalDateTime && right instanceof Duration ) {
return ((LocalDateTime) left).minus( (Duration) right);
代码示例来源:origin: org.jbpm/jbpm-flow
startAtDelayDur = Duration.between(OffsetDateTime.now(), endTime.minus(period));
代码示例来源:origin: otto-de/edison-microservice
@Test
public void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() throws Exception {
// given
repository.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost"));
repository.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost"));
// when
final List<JobInfo> jobInfos = repository.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS));
// then
assertThat(jobInfos, IsCollectionWithSize.hasSize(1));
assertThat(jobInfos.get(0).getJobId(), is("deadJob"));
}
代码示例来源:origin: org.threeten/threeten-extra
try {
OffsetDateTime end = OffsetDateTime.parse(endStr);
return Interval.of(end.minus(amount).toInstant(), end.toInstant());
} catch (DateTimeParseException ex) {
Instant start = end.plusSeconds(move).atOffset(ZoneOffset.UTC).minus(amount).toInstant().minusSeconds(move);
return Interval.of(start, end);
代码示例来源:origin: otto-de/edison-microservice
@Test
public void shouldAppendErrorMessageAndSetErrorStatus() {
OffsetDateTime now = OffsetDateTime.now(clock);
OffsetDateTime earlier = now.minus(10, MINUTES);
JobMessage message = JobMessage.jobMessage(Level.ERROR, "Error: Out of hunk", now);
JobInfo jobInfo = defaultJobInfo()
.setLastUpdated(earlier)
.build();
when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo));
// when
jobService.appendMessage(JOB_ID, message);
// then
verify(jobRepository).appendMessage(JOB_ID, message);
verify(jobRepository).setJobStatus(JOB_ID, JobInfo.JobStatus.ERROR);
}
代码示例来源:origin: otto-de/edison-microservice
@Test
public void shouldNotChangeStatusToOKWhenOnlyAppendingAMessage() {
OffsetDateTime now = OffsetDateTime.now(clock);
OffsetDateTime earlier = now.minus(10, MINUTES);
JobMessage message = JobMessage.jobMessage(Level.INFO, "Some info message", now);
JobInfo jobInfo = defaultJobInfo()
.setLastUpdated(earlier)
.setStatus(JobInfo.JobStatus.SKIPPED)
.build();
when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo));
// when
jobService.appendMessage(JOB_ID, message);
// then
verify(jobRepository).appendMessage(JOB_ID, message);
verifyNoMoreInteractions(jobRepository);
}
代码示例来源:origin: net.aholbrook.paseto/core
@Override
public void check(Token token, VerificationContext context) {
OffsetDateTime time = this.time == null ? OffsetDateTime.now(Clock.systemUTC()) : this.time;
// If no expiry time was set, then we treat the token as expired.
if (token.getExpiration() == null) {
throw new MissingClaimException(Token.CLAIM_EXPIRATION, NAME, token);
}
// Check "Not Before" if provided.
if (token.getNotBefore() != null) {
if (token.getNotBefore().minus(allowableDrift).isAfter(time)) {
throw new NotYetValidTokenException(token.getNotBefore(), NAME, token);
}
}
// Note: issued at times can be checked with the IssuedInPast rule.
// Finally we check the expiration time.
if (token.getExpiration().isBefore(time)) {
throw new ExpiredTokenException(token.getExpiration(), NAME, token);
}
}
}
代码示例来源:origin: Silverpeas/Silverpeas-Core
@Override
protected OffsetDateTime computeTriggeringDate() {
if (nextTriggeringDate != null && !nextTriggeringDate.isBefore(OffsetDateTime.now())) {
return nextTriggeringDate;
}
final ContributionModel model = getContribution().getModel();
final ZoneId userZoneId = User.getById(getUserId()).getUserPreferences().getZoneId();
ZonedDateTime sinceDateTime = ZonedDateTime.now(userZoneId)
.plus(this.duration, requireNonNull(this.timeUnit.toChronoUnit()));
OffsetDateTime propertyDateTime;
try {
propertyDateTime =
applyFilterOnTemporalType(model.filterByType(getContributionProperty(), sinceDateTime),
userZoneId);
} catch (NoSuchPropertyException e) {
propertyDateTime =
applyFilterOnTemporalType(model.filterByType(getContributionProperty()), userZoneId);
}
return
!propertyDateTime.isBefore(sinceDateTime.toOffsetDateTime()) ?
propertyDateTime.minus(this.duration, requireNonNull(this.timeUnit.toChronoUnit())) :
null;
}
内容来源于网络,如有侵权,请联系作者删除!