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

The following examples show how to use java.time.ZonedDateTime#plusMinutes() . 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: ExecutionTimeCron4jIntegrationTest.java    From cron-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Issue #37: nextExecution not calculating correct time.
 */
@Test
public void testEvery15Minutes() {
    ZonedDateTime lastRun = ZonedDateTime.now();
    final ExecutionTime executionTime = ExecutionTime.forCron(cron4jCronParser.parse(EVERY_15_MINUTES));

    // iterate through the next 75 minutes so we roll over the top of the hour
    // and make sure the next run time is always in the future from the prior run time
    for (int i = 0; i < 75; i++) {

        final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(lastRun);
        if (nextExecution.isPresent()) {
            final ZonedDateTime nextRun = nextExecution.get();
            log.debug(LOG_LAST_RUN, lastRun);
            log.debug(LOG_NEXT_RUN, nextRun);

            assertTrue(nextRun.getMinute() % 15 == 0);
            assertTrue(lastRun.isBefore(nextRun));
            lastRun = lastRun.plusMinutes(1);
        } else {
            fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
        }
    }
}
 
Example 2
Source File: ColumnTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test()
public void testSelectWithParallelProcessing() {
    final ZonedDateTime start = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT"));
    final ZonedDateTime end = start.plusMinutes(1000000);
    final Duration step = Duration.ofMinutes(1);
    final Index<ZonedDateTime> colKeys = Range.of(start, end, step).toIndex(ZonedDateTime.class);
    final DataFrame<String,ZonedDateTime> frame = DataFrame.of("C", colKeys, Double.class).applyDoubles(v -> Math.random() * 100);
    final long expectedCount = colKeys.keys().filter(t -> t.getDayOfWeek() == DayOfWeek.MONDAY).count();
    final DataFrame<String,ZonedDateTime> select1 = frame.cols().parallel().select(col -> col.key().getDayOfWeek() == DayOfWeek.MONDAY);
    final DataFrame<String,ZonedDateTime> select2 = frame.cols().sequential().select(col -> col.key().getDayOfWeek() == DayOfWeek.MONDAY);
    Assert.assertEquals(select1.colCount(), expectedCount, "Selection 1 has expected column count");
    Assert.assertEquals(select2.colCount(), expectedCount, "Selection 1 has expected column count");
    Assert.assertEquals(select1.rowCount(), 1, "Selection 1 has expected row count");
    Assert.assertEquals(select2.rowCount(), 1, "Selection 1 has expected row count");
    DataFrameAsserts.assertEqualsByIndex(select1, select2);
}
 
Example 3
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 4
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_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), 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_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 6
Source File: TimeIterator.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Increase the given time by {@code units}, which must be positive, of {@code granularity}
 */
public static ZonedDateTime inc(ZonedDateTime time, Granularity granularity, long units) {
  switch (granularity) {
    case MINUTE:
      return time.plusMinutes(units);
    case HOUR:
      return time.plusHours(units);
    case DAY:
      return time.plusDays(units);
    case MONTH:
      return time.plusMonths(units);
  }
  throw new RuntimeException("Unsupported granularity: " + granularity);
}
 
Example 7
Source File: MaintenanceScheduleHelperTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Verifies that there is no valid maintenance window available, scheduled before current time")
public void validateMaintenanceScheduleBeforeCurrentTime() {
    ZonedDateTime currentTime = ZonedDateTime.now();
    currentTime = currentTime.plusMinutes(-30);
    final String cronSchedule = String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(),
            currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear());
    final String duration = "00:10";
    final String timezone = ZonedDateTime.now().getOffset().getId().replace("Z", "+00:00");
    assertThatThrownBy(
            () -> MaintenanceScheduleHelper.validateMaintenanceSchedule(cronSchedule, duration, timezone))
                    .isInstanceOf(InvalidMaintenanceScheduleException.class)
                    .hasMessage("No valid maintenance window available after current time");
}
 
Example 8
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 9
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 10
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 11
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 12
Source File: ExecutionTimeQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #136: Bug exposed at PR #136
 * https://github.com/jmrozanec/cron-utils/pull/136
 * Reported case: when executing isMatch for a given range of dates,
 * if date is invalid, we get an exception, not a boolean as response.
 */
@Test
public void validateIsMatchForRangeOfDates() {
    final Cron cron = parser.parse("* * * 05 05 ? 2004");
    final ExecutionTime executionTime = ExecutionTime.forCron(cron);
    ZonedDateTime start = ZonedDateTime.of(2004, 5, 5, 23, 55, 0, 0, ZoneId.of("UTC"));
    final ZonedDateTime end = ZonedDateTime.of(2004, 5, 6, 1, 0, 0, 0, ZoneId.of("UTC"));
    while (start.compareTo(end) < 0) {
        executionTime.isMatch(start);
        start = start.plusMinutes(1);
    }
}
 
Example 13
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 14
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), 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_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), 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_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 17
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
Example 18
Source File: DateTime.java    From baleen with Apache License 2.0 4 votes vote down vote up
private void processDayMonthTime(TextBlock block) {
  Pattern dayMonthTime =
      Pattern.compile(
          "\\b"
              + DAYS
              + "([0-2]?[0-9]|3[01])\\s*"
              + DATE_SUFFIXES
              + "?\\s+"
              + MONTHS
              + ",?\\s+(\\d{4}|'?\\d{2})\\s+([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?\\s*(Z|"
              + TIME_ZONES
              + ")?\\b",
          Pattern.CASE_INSENSITIVE);
  Matcher m = dayMonthTime.matcher(block.getCoveredText());

  while (m.find()) {
    ZoneId zone;
    if (m.group(20) == null) {
      zone = ZoneId.of("Z");
    } else {
      zone = TimeZone.getTimeZone(m.group(20)).toZoneId();
    }

    if (m.group(19) != null) {
      ZonedDateTime zdt =
          ZonedDateTime.of(
              DateTimeUtils.asYear(m.group(16)).getValue(),
              DateTimeUtils.asMonth(m.group(3)).getValue(),
              Integer.parseInt(m.group(1)),
              Integer.parseInt(m.group(17)),
              Integer.parseInt(m.group(18)),
              Integer.parseInt(m.group(19)),
              0,
              zone);

      createDateTime(block, m.start(), m.end(), zdt);
    } else {
      ZonedDateTime zdtStart =
          ZonedDateTime.of(
              DateTimeUtils.asYear(m.group(16)).getValue(),
              DateTimeUtils.asMonth(m.group(3)).getValue(),
              Integer.parseInt(m.group(1)),
              Integer.parseInt(m.group(17)),
              Integer.parseInt(m.group(18)),
              0,
              0,
              zone);

      ZonedDateTime zdtEnd = zdtStart.plusMinutes(1);

      createDateTime(block, m.start(), m.end(), zdtStart, zdtEnd);
    }
  }
}
 
Example 19
Source File: DateTime.java    From baleen with Apache License 2.0 4 votes vote down vote up
private void processMonthDayTime(TextBlock block) {
  Pattern monthDayTime =
      Pattern.compile(
          "\\b"
              + MONTHS
              + "\\s+([0-2]?[0-9]|3[01])\\s*"
              + DATE_SUFFIXES
              + "?,?\\s+(\\d{4}|'?\\d{2})\\s+([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?\\s*(Z|"
              + TIME_ZONES
              + ")?\\b",
          Pattern.CASE_INSENSITIVE);
  Matcher m = monthDayTime.matcher(block.getCoveredText());

  while (m.find()) {
    ZoneId zone;
    if (m.group(20) == null) {
      zone = ZoneId.of("Z");
    } else {
      zone = TimeZone.getTimeZone(m.group(20)).toZoneId();
    }

    if (m.group(19) != null) {
      ZonedDateTime zdt =
          ZonedDateTime.of(
              DateTimeUtils.asYear(m.group(16)).getValue(),
              DateTimeUtils.asMonth(m.group(1)).getValue(),
              Integer.parseInt(m.group(14)),
              Integer.parseInt(m.group(17)),
              Integer.parseInt(m.group(18)),
              Integer.parseInt(m.group(19)),
              0,
              zone);

      createDateTime(block, m.start(), m.end(), zdt);
    } else {
      ZonedDateTime zdtStart =
          ZonedDateTime.of(
              DateTimeUtils.asYear(m.group(16)).getValue(),
              DateTimeUtils.asMonth(m.group(1)).getValue(),
              Integer.parseInt(m.group(14)),
              Integer.parseInt(m.group(17)),
              Integer.parseInt(m.group(18)),
              0,
              0,
              zone);

      ZonedDateTime zdtEnd = zdtStart.plusMinutes(1);

      createDateTime(block, m.start(), m.end(), zdtStart, zdtEnd);
    }
  }
}
 
Example 20
Source File: AbstractIntegrationTest.java    From hawkbit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Gets a valid cron expression describing a schedule with a single
 * maintenance window, starting specified number of minutes after current
 * time.
 *
 * @param minutesToAdd
 *            is the number of minutes after the current time
 *
 * @return {@link String} containing a valid cron expression.
 */
protected static String getTestSchedule(final int minutesToAdd) {
    ZonedDateTime currentTime = ZonedDateTime.now();
    currentTime = currentTime.plusMinutes(minutesToAdd);
    return String.format("%d %d %d %d %d ? %d", currentTime.getSecond(), currentTime.getMinute(),
            currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear());
}