Java Code Examples for java.time.ZonedDateTime#plusSeconds()

The following examples show how to use java.time.ZonedDateTime#plusSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutionTimeQuartzWithDayOfYearExtensionIntegrationTest.java    From cron-utils with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomQuarterlySchedule() {
    final ZonedDateTime firstDayOf2016 = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, UTC);
    final ZonedDateTime startWithLastDayOf2015 = ZonedDateTime.of(2015, 12, 31, 0, 0, 0, 0, UTC);
    final String customQuarterlyStartingWithDay47OfYear = "0 0 0 ? * ? * 47/91";
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(customQuarterlyStartingWithDay47OfYear));
    final ZonedDateTime[] expectedExecutionTimes = new ZonedDateTime[4];
    for (int j = 0; j < 4; j++) {
        expectedExecutionTimes[j] = firstDayOf2016.withDayOfYear(47 + j * 91);
    }
    ZonedDateTime start = startWithLastDayOf2015;
    for (final ZonedDateTime expectedExecutionTime : expectedExecutionTimes) {
        final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(start);
        if (nextExecution.isPresent()) {
            final ZonedDateTime actual = nextExecution.get();
            assertEquals(expectedExecutionTime, actual);
            start = expectedExecutionTime.plusSeconds(1);
        } else {
            fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
        }
    }
}
 
Example 2
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 3
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 4
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 5
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 6
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 7
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 8
Source File: TimerExecutor.java    From TelegramApi with MIT License 5 votes vote down vote up
/**
 * Find out next with time offset
 *
 * @param hourOffset hour offset
 * @param minOffset  minute offset
 * @param secOffset  second offset
 * @return time in second to wait
 * @note It will add one minute extra until next time is bigger than target time
 */
private long computNextTime(int hourOffset, int minOffset, int secOffset) {
    final LocalDateTime localNow = LocalDateTime.now();
    final ZoneId currentZone = ZoneId.systemDefault();
    final ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.plusHours(hourOffset)
            .plusMinutes(minOffset).plusSeconds(secOffset);
    while (zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusSeconds(5);
    }

    final Duration duration = Duration.between(zonedNow, zonedNextTarget);
    return duration.getSeconds();
}
 
Example 9
Source File: ExecutionTimeQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Test for issue #19
 * https://github.com/jmrozanec/cron-utils/issues/19
 * Reported case: When nextExecution shifts to 32nd day (e.g. 2015-01-31 23:59:59 + 00:00:01), JodaTime will throw an exception
 * Expected: should shift one month
 */
@Test
public void testShiftTo32ndDay() {
    final String expression = "0/1 * * 1/1 * ? *";  // every second every day
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(expression));

    final ZonedDateTime now = ZonedDateTime.of(2015, 1, 31, 23, 59, 59, 0, UTC);
    final ZonedDateTime expected = now.plusSeconds(1);
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now);
    if (nextExecution.isPresent()) {
        assertEquals(expected, nextExecution.get());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
Example 10
Source File: InsightsUtils.java    From Insights with Apache License 2.0 5 votes vote down vote up
public static Long getStartEpochTime() {
	ZonedDateTime now = ZonedDateTime.now(zoneId);

	ZonedDateTime todayStart = now.toLocalDate().atStartOfDay(zoneId);
	todayStart = todayStart.plusSeconds(1);
	return todayStart.toInstant().toEpochMilli();
}
 
Example 11
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 12
Source File: ExecutionTimeQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Test for issue #19
 * https://github.com/jmrozanec/cron-utils/issues/19
 * Reported case: When nextExecution shifts to the 24th hour (e.g. 23:59:59 + 00:00:01), JodaTime will throw an exception
 * Expected: should shift one day
 */
@Test
public void testShiftTo24thHour() {
    final String expression = "0/1 * * 1/1 * ? *";  // every second every day
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(expression));

    final ZonedDateTime now = ZonedDateTime.of(LocalDate.of(2016, 8, 5), LocalTime.of(23, 59, 59, 0), UTC);
    final ZonedDateTime expected = now.plusSeconds(1);
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now);
    if (nextExecution.isPresent()) {
        assertEquals(expected, nextExecution.get());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
Example 13
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 14
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 15
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 17
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
}
 
Example 18
Source File: TestkitExamplesTest.java    From exonum-java-binding with Apache License 2.0 4 votes vote down vote up
@Test
void timeOracleTest() {
  String timeServiceName = "time-service";
  int timeServiceId = 10;
  ZonedDateTime initialTime = ZonedDateTime.now(ZoneOffset.UTC);
  FakeTimeProvider timeProvider = FakeTimeProvider.create(initialTime);
  try (TestKit testKit = TestKit.builder()
      .withDeployedArtifact(ARTIFACT_ID, ARTIFACT_FILENAME)
      .withService(ARTIFACT_ID, SERVICE_NAME, SERVICE_ID)
      .withTimeService(timeServiceName, timeServiceId, timeProvider)
      .withArtifactsDirectory(ARTIFACTS_DIR)
      .build()) {
    // Create an empty block
    testKit.createBlock();
    // The time service submitted its first transaction in `afterCommit`
    // method, but it has not been executed yet
    Optional<ZonedDateTime> consolidatedTime1 =
        getConsolidatedTime(testKit, timeServiceName);
    // No time is available till the time service transaction is processed
    assertThat(consolidatedTime1).isEmpty();

    // Increase the time value
    ZonedDateTime time1 = initialTime.plusSeconds(1);
    timeProvider.setTime(time1);
    testKit.createBlock();
    // The time service submitted its second transaction. The first must
    // have been executed, with consolidated time now available and equal to
    // initialTime
    Optional<ZonedDateTime> consolidatedTime2 =
        getConsolidatedTime(testKit, timeServiceName);
    assertThat(consolidatedTime2).hasValue(initialTime);

    // Increase the time value
    ZonedDateTime time2 = initialTime.plusSeconds(1);
    timeProvider.setTime(time2);
    testKit.createBlock();
    // The time service submitted its third transaction, and processed the
    // second one. The consolidated time must be equal to time1
    Optional<ZonedDateTime> consolidatedTime3 =
        getConsolidatedTime(testKit, timeServiceName);
    assertThat(consolidatedTime3).hasValue(time1);
  }
}
 
Example 19
Source File: DefaultAuthenticationTokenService.java    From jersey-jwt-springsecurity with MIT License 2 votes vote down vote up
/**
 * Calculate the expiration date for a token.
 *
 * @param issuedDate
 * @return
 */
private ZonedDateTime calculateExpirationDate(ZonedDateTime issuedDate) {
    return issuedDate.plusSeconds(validFor);
}
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link java.time.ZonedDateTime} that is {@code seconds} seconds after this date/time.
 *
 * @param self    an ZonedDateTime
 * @param seconds the number of seconds to add
 * @return a ZonedDateTime
 * @since 2.5.0
 */
public static ZonedDateTime plus(final ZonedDateTime self, long seconds) {
    return self.plusSeconds(seconds);
}