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

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

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

OffsetDateTime.plusSeconds介绍

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

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

代码示例

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

sb.append("; Max-Age=").append(cookieValue.getCookieMaxAge());
OffsetDateTime expires = (maxAge != 0)
    ? OffsetDateTime.now().plusSeconds(maxAge)
    : Instant.EPOCH.atOffset(ZoneOffset.UTC);
sb.append("; Expires=")

代码示例来源:origin: prontera/spring-cloud-rest-tcc

@Transactional(rollbackFor = Exception.class)
public UserBalanceTcc trying(User user, long amount, long expireSeconds) {
  Preconditions.checkNotNull(user);
  Preconditions.checkNotNull(user.getId());
  Preconditions.checkArgument(amount > 0);
  final int isLock = userMapper.consumeBalance(user.getId(), amount);
  if (isLock == 0) {
    Shift.fatal(StatusCode.INSUFFICIENT_BALANCE);
  }
  final UserBalanceTcc tcc = new UserBalanceTcc();
  tcc.setAmount(amount);
  tcc.setStatus(TccStatus.TRY);
  tcc.setUserId(user.getId());
  tcc.setExpireTime(OffsetDateTime.now().plusSeconds(expireSeconds));
  persistNonNullProperties(tcc);
  return tcc;
}

代码示例来源:origin: prontera/spring-cloud-rest-tcc

@Transactional(rollbackFor = Exception.class)
public ProductStockTcc trying(Product product, long expireSeconds) {
  Preconditions.checkNotNull(product);
  Preconditions.checkNotNull(product.getId());
  Preconditions.checkArgument(expireSeconds > 0);
  final int isLock = productMapper.consumeStock(product.getId());
  if (isLock == 0) {
    Shift.fatal(StatusCode.INSUFFICIENT_PRODUCT);
  }
  final ProductStockTcc tcc = new ProductStockTcc();
  // 每次下单默认只能1个
  tcc.setStock(1);
  tcc.setStatus(TccStatus.TRY);
  tcc.setProductId(product.getId());
  tcc.setExpireTime(OffsetDateTime.now().plusSeconds(expireSeconds));
  persistNonNullProperties(tcc);
  return tcc;
}

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

@Test(timeout=10000)
public void testTimerStartDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
  byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
  String processContent = new String(content, "UTF-8");
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString());
  Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
  resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
  resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
  KieBase kbase = createKnowledgeBaseFromResources(resource);
  ksession = createKnowledgeSession(kbase);
  ksession.addEventListener(countDownListener);
  final List<Long> list = new ArrayList<Long>();
  ksession.addEventListener(new DefaultProcessEventListener() {
    public void beforeProcessStarted(ProcessStartedEvent event) {
      list.add(event.getProcessInstance().getId());
    }
  });
  assertThat(list.size()).isEqualTo(0);
  countDownListener.waitTillCompleted();
  assertThat(list.size()).isEqualTo(1);
}

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

@Test(timeout=10000)
public void testIntermediateCatchEventTimerDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
  KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateCatchEventTimerDateISO.bpmn2");
  ksession = createKnowledgeSession(kbase);
  ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
  ksession.addEventListener(countDownListener);
  HashMap<String, Object> params = new HashMap<String, Object>();
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  params.put("date", plusTwoSeconds.toString());
  ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
  assertProcessInstanceActive(processInstance);
  // now wait for 1 second for timer to trigger
  countDownListener.waitTillCompleted();
  assertProcessInstanceFinished(processInstance, ksession);
}

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

@Test(timeout=10000)
public void testTimerBoundaryEventDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
  KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-TimerBoundaryEventDateISO.bpmn2");
  ksession = createKnowledgeSession(kbase);
  ksession.addEventListener(countDownListener);
  ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
  HashMap<String, Object> params = new HashMap<String, Object>();
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  params.put("date", plusTwoSeconds.toString());
  ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent", params);
  assertProcessInstanceActive(processInstance);
  countDownListener.waitTillCompleted();
  ksession = restoreSession(ksession, true);
  assertProcessInstanceFinished(processInstance, ksession);
}

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

/**
 * Returns an {@link java.time.OffsetDateTime} that is {@code seconds} seconds after this date/time.
 *
 * @param self    an OffsetDateTime
 * @param seconds the number of seconds to add
 * @return an OffsetDateTime
 * @since 2.5.0
 */
public static OffsetDateTime plus(final OffsetDateTime self, long seconds) {
  return self.plusSeconds(seconds);
}

代码示例来源:origin: net.dv8tion/JDA

@Override
public OffsetDateTime getTime()
{
  return time.plusSeconds(0L);
}

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

/**
 * Returns a copy of this {@code OffsetDateTime} with the specified period in seconds subtracted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param seconds  the seconds to subtract, may be negative
 * @return an {@code OffsetDateTime} based on this date-time with the seconds subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public OffsetDateTime minusSeconds(long seconds) {
  return (seconds == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-seconds));
}

代码示例来源:origin: net.dv8tion/JDA

@Override
public OffsetDateTime getEditedTimestamp()
{
  return editedTime.plusSeconds(0L);
}

代码示例来源:origin: com.sqlapp/sqlapp-core

@Override
protected OffsetDateTime getNext() {
  return current.plusSeconds(this.step.intValue());
}

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

OffsetDateTime dt = OffsetDateTime.of(1900, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(value);
System.out.printlf(dt.toString());

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

OffsetDateTime dt = OffsetDateTime.of(1900, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(value);
System.out.printlf(dt.toString());

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

@Test
public void shouldFindAllJobTypes() throws Exception {
  // Given
  final OffsetDateTime now = OffsetDateTime.now();
  final JobInfo eins = someRunningJobInfo("jobEins", "someJobTypeEins", now);
  final JobInfo zwei = someRunningJobInfo("jobZwei", "someJobTypeZwei", now.plusSeconds(1));
  final JobInfo drei = someRunningJobInfo("jobDrei", "someJobTypeDrei", now.plusSeconds(2));
  final JobInfo vierWithTypeDrei = someRunningJobInfo("jobVier", "someJobTypeDrei", now.plusSeconds(3));
  repo.createOrUpdate(eins);
  repo.createOrUpdate(zwei);
  repo.createOrUpdate(drei);
  repo.createOrUpdate(vierWithTypeDrei);
  // When
  final List<String> allJobIds = repo.findAllJobIdsDistinct();
  // Then
  assertThat(allJobIds, hasSize(3));
  assertThat(allJobIds, containsInAnyOrder("jobEins", "jobZwei", "jobVier"));
}

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

@Test
public void shouldFindRunningWithoutUpdateSince() {
  // given
  final JobInfo foo = jobInfo("http://localhost/foo", "T_FOO");
  final JobInfo bar = someRunningJobInfo("http://localhost/bar", "T_BAR", now());
  final JobInfo foobar = someRunningJobInfo("http://localhost/foobar", "T_BAR", now().plusSeconds(3));
  repo.createOrUpdate(foo);
  repo.createOrUpdate(bar);
  repo.createOrUpdate(foobar);
  // when
  final List<JobInfo> infos = repo.findRunningWithoutUpdateSince(now().plusSeconds(2));
  // then
  assertThat(infos, hasSize(1));
  assertThat(infos.get(0), is(bar));
}

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

@Test
public void shouldFindLatestDistinct() throws Exception {
  // Given
  final OffsetDateTime now = OffsetDateTime.now();
  final JobInfo eins = someRunningJobInfo("http://localhost/eins", "someJobType", now);
  final JobInfo zwei = someRunningJobInfo("http://localhost/zwei", "someOtherJobType", now.plusSeconds(1));
  final JobInfo drei = someRunningJobInfo("http://localhost/drei", "nextJobType", now.plusSeconds(2));
  final JobInfo vier = someRunningJobInfo("http://localhost/vier", "someJobType", now.plusSeconds(3));
  final JobInfo fuenf = someRunningJobInfo("http://localhost/fuenf", "someJobType", now.plusSeconds(4));
  repo.createOrUpdate(eins);
  repo.createOrUpdate(zwei);
  repo.createOrUpdate(drei);
  repo.createOrUpdate(vier);
  repo.createOrUpdate(fuenf);
  // When
  final List<JobInfo> latestDistinct = repo.findLatestJobsDistinct();
  // Then
  assertThat(latestDistinct, hasSize(3));
  assertThat(latestDistinct, containsInAnyOrder(fuenf, zwei, drei));
}

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

@Test(timeout=10000)
public void testTimerStartDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
  byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
  String processContent = new String(content, "UTF-8");
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString());
  Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
  resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
  resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
  KieBase kbase = createKnowledgeBaseFromResources(resource);
  ksession = createKnowledgeSession(kbase);
  ksession.addEventListener(countDownListener);
  final List<Long> list = new ArrayList<Long>();
  ksession.addEventListener(new DefaultProcessEventListener() {
    public void beforeProcessStarted(ProcessStartedEvent event) {
      list.add(event.getProcessInstance().getId());
    }
  });
  assertThat(list.size()).isEqualTo(0);
  countDownListener.waitTillCompleted();
  assertThat(list.size()).isEqualTo(1);
}

代码示例来源:origin: RoboZonky/robozonky

@Test
void refreshesShortlyAfterMidnight() {
  final StonkyJob instance = new StonkyJob();
  final Duration startIn = instance.startIn();
  final OffsetDateTime timeToStartOn = OffsetDateTime.now().plus(startIn);
  final OffsetDateTime timeToStartBefore = timeToStartOn.plusSeconds(1000);
  final OffsetDateTime tomorrow = LocalDate.now().plusDays(1).atStartOfDay(Defaults.ZONE_ID).toOffsetDateTime();
  assertThat(timeToStartOn)
      .isAfter(tomorrow)
      .isBefore(timeToStartBefore);
}

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

@Test(timeout=10000)
public void testIntermediateCatchEventTimerDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
  KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateCatchEventTimerDateISO.bpmn2");
  ksession = createKnowledgeSession(kbase);
  ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
  ksession.addEventListener(countDownListener);
  HashMap<String, Object> params = new HashMap<String, Object>();
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  params.put("date", plusTwoSeconds.toString());
  ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
  assertProcessInstanceActive(processInstance);
  // now wait for 1 second for timer to trigger
  countDownListener.waitTillCompleted();
  assertProcessInstanceFinished(processInstance, ksession);
}

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

@Test(timeout=10000)
public void testTimerBoundaryEventDateISO() throws Exception {
  NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
  KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-TimerBoundaryEventDateISO.bpmn2");
  ksession = createKnowledgeSession(kbase);
  ksession.addEventListener(countDownListener);
  ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
  HashMap<String, Object> params = new HashMap<String, Object>();
  OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  params.put("date", plusTwoSeconds.toString());
  ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent", params);
  assertProcessInstanceActive(processInstance);
  countDownListener.waitTillCompleted();
  ksession = restoreSession(ksession, true);
  assertProcessInstanceFinished(processInstance, ksession);
}

相关文章