java.time.OffsetDateTime.minus()方法的使用及代码示例

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

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

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

  1. private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
  2. checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
  3. Date actualCreatedAfter = createdAfter;
  4. if (createdInLast != null) {
  5. actualCreatedAfter = Date.from(
  6. OffsetDateTime.now(clock)
  7. .minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
  8. .toInstant());
  9. }
  10. builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
  11. }

代码示例来源:origin: kiegroup/jbpm

  1. startAtDelayDur = Duration.between(OffsetDateTime.now(), endTime.minus(period));

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

  1. private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
  2. checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
  3. Date actualCreatedAfter = createdAfter;
  4. if (createdInLast != null) {
  5. actualCreatedAfter = Date.from(
  6. OffsetDateTime.now(clock)
  7. .minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
  8. .toInstant());
  9. }
  10. builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
  11. }

代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene

  1. private OffsetDateTime next(OffsetDateTime from, boolean forward) {
  2. OffsetDateTime to;
  3. if (forward) {
  4. to = this._intervalDate == null ? from : from.plus(this._intervalDate);
  5. to = this._intervalTime == null ? to : to.plus(this._intervalTime);
  6. if (this._end != null && to.isAfter(this._end)) to = this._end;
  7. } else {
  8. to = this._intervalDate == null ? from : from.minus(this._intervalDate);
  9. to = this._intervalTime == null ? to : to.minus(this._intervalTime);
  10. if (this._end != null && to.isBefore(this._start)) to = this._start;
  11. }
  12. return to;
  13. }

代码示例来源:origin: org.n52.wps/engine

  1. @Override
  2. public void run() {
  3. list(basePath).filter(shouldBeDeleted(OffsetDateTime.now().minus(duration))).forEach(this::delete);
  4. }

代码示例来源:origin: zolyfarkas/spf4j

  1. String strNrDays = validatorConfigs.get("maxNrOfDaysBackCheckForCompatibility");
  2. if (strNrDays == null) {
  3. instantToGoBack = Instant.now().atOffset(ZoneOffset.UTC).minus(1, ChronoUnit.YEARS).toInstant();
  4. } else {
  5. instantToGoBack = Instant.now().atOffset(ZoneOffset.UTC)
  6. .minus(Integer.parseInt(strNrDays), ChronoUnit.DAYS).toInstant();

代码示例来源:origin: net.aholbrook.paseto/core

  1. @Override
  2. public void check(Token token, VerificationContext context) {
  3. OffsetDateTime time = this.time == null ? OffsetDateTime.now(Clock.systemUTC()) : this.time;
  4. if (token.getIssuedAt() == null) {
  5. throw new MissingClaimException(Token.CLAIM_ISSUED_AT, NAME, token);
  6. }
  7. if (token.getIssuedAt().minus(allowableDrift).isAfter(time)) {
  8. throw new IssuedInFutureException(time, token.getIssuedAt(), NAME, token);
  9. }
  10. }
  11. }

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

  1. return ((ZonedDateTime) left).minus( (Period) right);
  2. } else if ( left instanceof OffsetDateTime && right instanceof Period ) {
  3. return ((OffsetDateTime) left).minus( (Period) right);
  4. } else if ( left instanceof LocalDateTime && right instanceof Period ) {
  5. return ((LocalDateTime) left).minus( (Period) right);
  6. return ((ZonedDateTime) left).minus( (Duration) right);
  7. } else if ( left instanceof OffsetDateTime && right instanceof Duration ) {
  8. return ((OffsetDateTime) left).minus( (Duration) right);
  9. } else if ( left instanceof LocalDateTime && right instanceof Duration ) {
  10. return ((LocalDateTime) left).minus( (Duration) right);

代码示例来源:origin: org.jbpm/jbpm-flow

  1. startAtDelayDur = Duration.between(OffsetDateTime.now(), endTime.minus(period));

代码示例来源:origin: otto-de/edison-microservice

  1. @Test
  2. public void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() throws Exception {
  3. // given
  4. repository.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost"));
  5. repository.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost"));
  6. // when
  7. final List<JobInfo> jobInfos = repository.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS));
  8. // then
  9. assertThat(jobInfos, IsCollectionWithSize.hasSize(1));
  10. assertThat(jobInfos.get(0).getJobId(), is("deadJob"));
  11. }

代码示例来源:origin: org.threeten/threeten-extra

  1. try {
  2. OffsetDateTime end = OffsetDateTime.parse(endStr);
  3. return Interval.of(end.minus(amount).toInstant(), end.toInstant());
  4. } catch (DateTimeParseException ex) {
  5. Instant start = end.plusSeconds(move).atOffset(ZoneOffset.UTC).minus(amount).toInstant().minusSeconds(move);
  6. return Interval.of(start, end);

代码示例来源:origin: otto-de/edison-microservice

  1. @Test
  2. public void shouldAppendErrorMessageAndSetErrorStatus() {
  3. OffsetDateTime now = OffsetDateTime.now(clock);
  4. OffsetDateTime earlier = now.minus(10, MINUTES);
  5. JobMessage message = JobMessage.jobMessage(Level.ERROR, "Error: Out of hunk", now);
  6. JobInfo jobInfo = defaultJobInfo()
  7. .setLastUpdated(earlier)
  8. .build();
  9. when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo));
  10. // when
  11. jobService.appendMessage(JOB_ID, message);
  12. // then
  13. verify(jobRepository).appendMessage(JOB_ID, message);
  14. verify(jobRepository).setJobStatus(JOB_ID, JobInfo.JobStatus.ERROR);
  15. }

代码示例来源:origin: otto-de/edison-microservice

  1. @Test
  2. public void shouldNotChangeStatusToOKWhenOnlyAppendingAMessage() {
  3. OffsetDateTime now = OffsetDateTime.now(clock);
  4. OffsetDateTime earlier = now.minus(10, MINUTES);
  5. JobMessage message = JobMessage.jobMessage(Level.INFO, "Some info message", now);
  6. JobInfo jobInfo = defaultJobInfo()
  7. .setLastUpdated(earlier)
  8. .setStatus(JobInfo.JobStatus.SKIPPED)
  9. .build();
  10. when(jobRepository.findOne(JOB_ID)).thenReturn(Optional.of(jobInfo));
  11. // when
  12. jobService.appendMessage(JOB_ID, message);
  13. // then
  14. verify(jobRepository).appendMessage(JOB_ID, message);
  15. verifyNoMoreInteractions(jobRepository);
  16. }

代码示例来源:origin: net.aholbrook.paseto/core

  1. @Override
  2. public void check(Token token, VerificationContext context) {
  3. OffsetDateTime time = this.time == null ? OffsetDateTime.now(Clock.systemUTC()) : this.time;
  4. // If no expiry time was set, then we treat the token as expired.
  5. if (token.getExpiration() == null) {
  6. throw new MissingClaimException(Token.CLAIM_EXPIRATION, NAME, token);
  7. }
  8. // Check "Not Before" if provided.
  9. if (token.getNotBefore() != null) {
  10. if (token.getNotBefore().minus(allowableDrift).isAfter(time)) {
  11. throw new NotYetValidTokenException(token.getNotBefore(), NAME, token);
  12. }
  13. }
  14. // Note: issued at times can be checked with the IssuedInPast rule.
  15. // Finally we check the expiration time.
  16. if (token.getExpiration().isBefore(time)) {
  17. throw new ExpiredTokenException(token.getExpiration(), NAME, token);
  18. }
  19. }
  20. }

代码示例来源:origin: Silverpeas/Silverpeas-Core

  1. @Override
  2. protected OffsetDateTime computeTriggeringDate() {
  3. if (nextTriggeringDate != null && !nextTriggeringDate.isBefore(OffsetDateTime.now())) {
  4. return nextTriggeringDate;
  5. }
  6. final ContributionModel model = getContribution().getModel();
  7. final ZoneId userZoneId = User.getById(getUserId()).getUserPreferences().getZoneId();
  8. ZonedDateTime sinceDateTime = ZonedDateTime.now(userZoneId)
  9. .plus(this.duration, requireNonNull(this.timeUnit.toChronoUnit()));
  10. OffsetDateTime propertyDateTime;
  11. try {
  12. propertyDateTime =
  13. applyFilterOnTemporalType(model.filterByType(getContributionProperty(), sinceDateTime),
  14. userZoneId);
  15. } catch (NoSuchPropertyException e) {
  16. propertyDateTime =
  17. applyFilterOnTemporalType(model.filterByType(getContributionProperty()), userZoneId);
  18. }
  19. return
  20. !propertyDateTime.isBefore(sinceDateTime.toOffsetDateTime()) ?
  21. propertyDateTime.minus(this.duration, requireNonNull(this.timeUnit.toChronoUnit())) :
  22. null;
  23. }

相关文章