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

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

本文整理了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

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

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

  1. @Transactional(rollbackFor = Exception.class)
  2. public UserBalanceTcc trying(User user, long amount, long expireSeconds) {
  3. Preconditions.checkNotNull(user);
  4. Preconditions.checkNotNull(user.getId());
  5. Preconditions.checkArgument(amount > 0);
  6. final int isLock = userMapper.consumeBalance(user.getId(), amount);
  7. if (isLock == 0) {
  8. Shift.fatal(StatusCode.INSUFFICIENT_BALANCE);
  9. }
  10. final UserBalanceTcc tcc = new UserBalanceTcc();
  11. tcc.setAmount(amount);
  12. tcc.setStatus(TccStatus.TRY);
  13. tcc.setUserId(user.getId());
  14. tcc.setExpireTime(OffsetDateTime.now().plusSeconds(expireSeconds));
  15. persistNonNullProperties(tcc);
  16. return tcc;
  17. }

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

  1. @Transactional(rollbackFor = Exception.class)
  2. public ProductStockTcc trying(Product product, long expireSeconds) {
  3. Preconditions.checkNotNull(product);
  4. Preconditions.checkNotNull(product.getId());
  5. Preconditions.checkArgument(expireSeconds > 0);
  6. final int isLock = productMapper.consumeStock(product.getId());
  7. if (isLock == 0) {
  8. Shift.fatal(StatusCode.INSUFFICIENT_PRODUCT);
  9. }
  10. final ProductStockTcc tcc = new ProductStockTcc();
  11. // 每次下单默认只能1个
  12. tcc.setStock(1);
  13. tcc.setStatus(TccStatus.TRY);
  14. tcc.setProductId(product.getId());
  15. tcc.setExpireTime(OffsetDateTime.now().plusSeconds(expireSeconds));
  16. persistNonNullProperties(tcc);
  17. return tcc;
  18. }

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

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

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

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

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

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

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

  1. /**
  2. * Returns an {@link java.time.OffsetDateTime} that is {@code seconds} seconds after this date/time.
  3. *
  4. * @param self an OffsetDateTime
  5. * @param seconds the number of seconds to add
  6. * @return an OffsetDateTime
  7. * @since 2.5.0
  8. */
  9. public static OffsetDateTime plus(final OffsetDateTime self, long seconds) {
  10. return self.plusSeconds(seconds);
  11. }

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

  1. @Override
  2. public OffsetDateTime getTime()
  3. {
  4. return time.plusSeconds(0L);
  5. }

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

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

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

  1. @Override
  2. public OffsetDateTime getEditedTimestamp()
  3. {
  4. return editedTime.plusSeconds(0L);
  5. }

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

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

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

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

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

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

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

  1. @Test
  2. public void shouldFindAllJobTypes() throws Exception {
  3. // Given
  4. final OffsetDateTime now = OffsetDateTime.now();
  5. final JobInfo eins = someRunningJobInfo("jobEins", "someJobTypeEins", now);
  6. final JobInfo zwei = someRunningJobInfo("jobZwei", "someJobTypeZwei", now.plusSeconds(1));
  7. final JobInfo drei = someRunningJobInfo("jobDrei", "someJobTypeDrei", now.plusSeconds(2));
  8. final JobInfo vierWithTypeDrei = someRunningJobInfo("jobVier", "someJobTypeDrei", now.plusSeconds(3));
  9. repo.createOrUpdate(eins);
  10. repo.createOrUpdate(zwei);
  11. repo.createOrUpdate(drei);
  12. repo.createOrUpdate(vierWithTypeDrei);
  13. // When
  14. final List<String> allJobIds = repo.findAllJobIdsDistinct();
  15. // Then
  16. assertThat(allJobIds, hasSize(3));
  17. assertThat(allJobIds, containsInAnyOrder("jobEins", "jobZwei", "jobVier"));
  18. }

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

  1. @Test
  2. public void shouldFindRunningWithoutUpdateSince() {
  3. // given
  4. final JobInfo foo = jobInfo("http://localhost/foo", "T_FOO");
  5. final JobInfo bar = someRunningJobInfo("http://localhost/bar", "T_BAR", now());
  6. final JobInfo foobar = someRunningJobInfo("http://localhost/foobar", "T_BAR", now().plusSeconds(3));
  7. repo.createOrUpdate(foo);
  8. repo.createOrUpdate(bar);
  9. repo.createOrUpdate(foobar);
  10. // when
  11. final List<JobInfo> infos = repo.findRunningWithoutUpdateSince(now().plusSeconds(2));
  12. // then
  13. assertThat(infos, hasSize(1));
  14. assertThat(infos.get(0), is(bar));
  15. }

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

  1. @Test
  2. public void shouldFindLatestDistinct() throws Exception {
  3. // Given
  4. final OffsetDateTime now = OffsetDateTime.now();
  5. final JobInfo eins = someRunningJobInfo("http://localhost/eins", "someJobType", now);
  6. final JobInfo zwei = someRunningJobInfo("http://localhost/zwei", "someOtherJobType", now.plusSeconds(1));
  7. final JobInfo drei = someRunningJobInfo("http://localhost/drei", "nextJobType", now.plusSeconds(2));
  8. final JobInfo vier = someRunningJobInfo("http://localhost/vier", "someJobType", now.plusSeconds(3));
  9. final JobInfo fuenf = someRunningJobInfo("http://localhost/fuenf", "someJobType", now.plusSeconds(4));
  10. repo.createOrUpdate(eins);
  11. repo.createOrUpdate(zwei);
  12. repo.createOrUpdate(drei);
  13. repo.createOrUpdate(vier);
  14. repo.createOrUpdate(fuenf);
  15. // When
  16. final List<JobInfo> latestDistinct = repo.findLatestJobsDistinct();
  17. // Then
  18. assertThat(latestDistinct, hasSize(3));
  19. assertThat(latestDistinct, containsInAnyOrder(fuenf, zwei, drei));
  20. }

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

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

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

  1. @Test
  2. void refreshesShortlyAfterMidnight() {
  3. final StonkyJob instance = new StonkyJob();
  4. final Duration startIn = instance.startIn();
  5. final OffsetDateTime timeToStartOn = OffsetDateTime.now().plus(startIn);
  6. final OffsetDateTime timeToStartBefore = timeToStartOn.plusSeconds(1000);
  7. final OffsetDateTime tomorrow = LocalDate.now().plusDays(1).atStartOfDay(Defaults.ZONE_ID).toOffsetDateTime();
  8. assertThat(timeToStartOn)
  9. .isAfter(tomorrow)
  10. .isBefore(timeToStartBefore);
  11. }

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

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

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

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

相关文章