Java Code Examples for java.time.LocalDateTime#minusMinutes()

The following examples show how to use java.time.LocalDateTime#minusMinutes() . 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: TCKLocalDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 2
Source File: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 3
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 4
Source File: ApplicationConfiguration.java    From spring-rest-black-market with MIT License 6 votes vote down vote up
public void load() {
    int amount = 100;
    LocalDateTime now = LocalDateTime.now();
    final LocalDateTime publishedAt = now.minusMinutes(PUBLISHING_TIME_MAX_DIFF * amount);

    SecurityUtils.run("system", "system", new String[]{"ROLE_ADMIN"}, () -> {
        if (!stableUsersOnly) {
            LocalDateTime at = publishedAt;
            for (int i = 0; i < amount; ++i) {
                User user = nextUser();
                userRepository.save(user);

                Ad ad = nextAd(user, at);
                adRepository.save(ad);

                at = ad.getPublishedAt();
            }
        }

        setupAdmin(publishedAt.minusMinutes(10));
        setupStableUser(publishedAt);
    });
}
 
Example 5
Source File: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 6
Source File: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 7
Source File: TCKLocalDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 8
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 9
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 10
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 11
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 12
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 13
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = 70; i > -70; i--) {
        LocalDateTime dt = base.minusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 14
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 15
Source File: TimeHelper.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a copy of the {@link LocalDateTime} adjusted to be compatible with the format output by
 * {@link #parseDateTimeFromSessionsForm}, i.e. either the time is 23:59, or the minute is 0 and the hour is not 0.
 * The date time is first rounded to the nearest hour, then the special case 00:00 is handled.
 * @param ldt The {@link LocalDateTime} to be adjusted for compatibility.
 * @return a copy of {@code ldt} adjusted for compatibility, or null if {@code ldt} is null.
 * @see #parseDateTimeFromSessionsForm
 */
public static LocalDateTime adjustLocalDateTimeForSessionsFormInputs(LocalDateTime ldt) {
    if (ldt == null) {
        return null;
    }
    if (ldt.getMinute() == 0 && ldt.getHour() != 0 || ldt.getMinute() == 59 && ldt.getHour() == 23) {
        return ldt;
    }

    // Round to the nearest hour
    LocalDateTime rounded;
    LocalDateTime floor = ldt.truncatedTo(ChronoUnit.HOURS);
    LocalDateTime ceiling = floor.plusHours(1);
    Duration distanceToCeiling = Duration.between(ldt, ceiling);
    if (distanceToCeiling.compareTo(Duration.ofMinutes(30)) <= 0) {
        rounded = ceiling;
    } else {
        rounded = floor;
    }

    // Adjust 00:00 -> 23:59
    if (rounded.getHour() == 0) {
        return rounded.minusMinutes(1);
    }
    return rounded;
}
 
Example 16
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.minusMinutes(1);
        min--;
        if (min == -1) {
            hour--;
            min = 59;

            if (hour == -1) {
                hour = 23;
            }
        }
        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 17
Source File: DurationTextTest.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Test
	public void testNiceDateText(){
		DurationText dtext = DurationText.createSimpleChineseDurationText();
		
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		LocalDateTime date = LocalDateTime.now();
		LocalDateTime date2 = date.minusSeconds(40);
		System.out.println("date: " + date.format(formatter)+", date2: " + date2.format(formatter));
		
//		Duration duration = Duration.ofSeconds(date2.until(date, ChronoUnit.SECONDS));
		String text = dtext.getText(date2, date);
		Assert.assertEquals("刚刚", text);
		
		date2 = date.minusMinutes(3);
		System.out.println("date: " + date.format(formatter)+", date2: " + date2.format(formatter));
		text = dtext.getText(date2, date);
		Assert.assertEquals("3分钟前", text);

		date2 = date.minusHours(4);
		text = dtext.getText(date2, date);
		Assert.assertEquals("4小时前", text);

		date2 = date.minusDays(32);
		text = dtext.getText(date2, date);
		Assert.assertEquals("32天前", text);
	}
 
Example 18
Source File: JobStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Simulate a job that has run longer than the next fire time such that it misfires, but will not fire again because
 * the end of the trigger window has passed.
 */
@Test
public void testTriggerPastDueMisfireButWillNotFire() throws Exception {
  JobDetail jobDetail = JobBuilder.newJob(MyNonConcurrentJob.class).storeDurably(true).build();
  jobStore.storeJob(jobDetail, false);

  ZoneId zone = ZoneId.systemDefault();

  Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow();
  LocalDateTime baseDateTime = LocalDateTime.ofInstant(baseFireTimeDate.toInstant(), zone);
  LocalDateTime startAt = baseDateTime.minusMinutes(5);
  LocalDateTime endAt = baseDateTime.minusMinutes(1);
  LocalDateTime nextFireTime = startAt.plusMinutes(1);

  SimpleScheduleBuilder simple = SimpleScheduleBuilder.simpleSchedule()
      .withIntervalInMinutes(1);
  OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger()
      .forJob(jobDetail)
      .withSchedule(simple)
      .startAt(Date.from(startAt.atZone(zone).toInstant()))
      .endAt(Date.from(endAt.atZone(zone).toInstant()))
      .build();

  // misfire the trigger and set the next fire time in the past
  trigger.updateAfterMisfire(null);
  trigger.setNextFireTime(Date.from(nextFireTime.atZone(zone).toInstant()));
  trigger.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT);
  jobStore.storeTrigger(trigger, false);

  List<OperableTrigger> acquiredTriggers =
      jobStore.acquireNextTriggers(baseFireTimeDate.getTime(), 4, 1000L);
  assertEquals(0, acquiredTriggers.size());
}
 
Example 19
Source File: ImportDateTime.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public LocalDateTime updateMinute(LocalDateTime datetime, String minute) {
  if (!Strings.isNullOrEmpty(minute)) {
    Matcher matcher = patternMonth.matcher(minute);
    if (matcher.find()) {
      Long minutes = Long.parseLong(matcher.group());
      if (minute.startsWith("+")) datetime = datetime.plusMinutes(minutes);
      else if (minute.startsWith("-")) datetime = datetime.minusMinutes(minutes);
      else datetime = datetime.withMinute(minutes.intValue());
    }
  }
  return datetime;
}
 
Example 20
Source File: JobStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Simulate a job that has run longer than the next fire time such that it misfires.
 */
@Test
public void testTriggerPastDueMisfire() throws Exception {
  JobDetail jobDetail = JobBuilder.newJob(MyNonConcurrentJob.class)
      .storeDurably(true)
      .build();
  jobStore.storeJob(jobDetail, false);

  ZoneId zone = ZoneId.systemDefault();

  Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow();
  LocalDateTime baseDateTime = LocalDateTime.ofInstant(baseFireTimeDate.toInstant(), zone);
  LocalDateTime startAt = baseDateTime.minusMinutes(5);
  LocalDateTime nextFireTime = startAt.plusMinutes(1);

  CronScheduleBuilder schedule = CronScheduleBuilder.cronSchedule("0 1 * * * ? *");
  OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger()
      .forJob(jobDetail)
      .withSchedule(schedule)
      .startAt(Date.from(startAt.atZone(zone).toInstant()))
      .build();

  // misfire the trigger and set the next fire time in the past
  trigger.updateAfterMisfire(null);
  trigger.setNextFireTime(Date.from(nextFireTime.atZone(zone).toInstant()));
  jobStore.storeTrigger(trigger, false);

  List<OperableTrigger> acquiredTriggers =
      jobStore.acquireNextTriggers(DateBuilder.evenMinuteDateAfterNow().getTime(), 4, 1000L);
  assertEquals(1, acquiredTriggers.size());
}