java.time.OffsetDateTime#minusHours ( )源码实例Demo

下面列出了java.time.OffsetDateTime#minusHours ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: blackduck-alert   文件: UpdateChecker.java
/**
 * The Date Alert has in the About will always be slightly before the Docker Hub date. So if the two are within 1 hour of each other, then we will consider them the same.
 */
private int compareDateStrings(String first, String second) {
    try {
        OffsetDateTime firstDate = parseDate(first, DOCKER_DATE_FORMAT);
        OffsetDateTime secondDate = parseDate(second, DOCKER_DATE_FORMAT);

        OffsetDateTime hourEarlier = firstDate.minusHours(1);
        OffsetDateTime hourLater = firstDate.plusHours(1);

        boolean secondIsWithinAnHourOfFirst = hourEarlier.isBefore(secondDate) && hourLater.isAfter(secondDate);

        if (secondIsWithinAnHourOfFirst) {
            return 0;
        }
        if (firstDate.isAfter(secondDate)) {
            return -1;
        } else if (firstDate.isBefore(secondDate)) {
            return 1;
        }
    } catch (ParseException e) {
        logger.debug("Could not parse the date strings with the format {}.", DOCKER_DATE_FORMAT);
        logger.debug(e.getMessage(), e);
    }
    return 0;
}
 
@Test
public void findByCreatedAtBetween() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime startDate = time.minusHours(1);
    OffsetDateTime endDate = time.plusHours(1);
    OffsetDateTime createdAt = time.minusHours(3);
    AlertNotificationModel entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    createdAt = time.plusMinutes(1);
    AlertNotificationModel entityToFind1 = createNotificationModel(createdAt);
    createdAt = time.plusMinutes(5);
    AlertNotificationModel entityToFind2 = createNotificationModel(createdAt);
    createdAt = time.plusHours(3);
    entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    notificationManager.saveAllNotifications(List.of(entityToFind1));
    notificationManager.saveAllNotifications(List.of(entityToFind2));

    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);

    assertEquals(2, foundList.size());
    assertNotificationModel(entityToFind1, foundList.get(0));
    assertNotificationModel(entityToFind2, foundList.get(1));
}
 
@Test
public void findByCreatedAtBetweenInvalidDate() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime startDate = time.minusHours(1);
    OffsetDateTime endDate = time.plusHours(1);
    OffsetDateTime createdAtEarlier = time.minusHours(5);
    AlertNotificationModel entity = createNotificationModel(createdAtEarlier);
    notificationManager.saveAllNotifications(List.of(entity));

    OffsetDateTime createdAtLater = time.plusHours(3);
    entity = createNotificationModel(createdAtLater);
    notificationManager.saveAllNotifications(List.of(entity));

    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);

    assertTrue(foundList.isEmpty());
}
 
@Test
public void findByCreatedAtBefore() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime searchDate = time.plusHours(1);
    OffsetDateTime createdAt = time.minusHours(5);
    AlertNotificationModel entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    OffsetDateTime createdAtLaterThanSearch = time.plusHours(3);
    entity = createNotificationModel(createdAtLaterThanSearch);
    notificationManager.saveAllNotifications(List.of(entity));

    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBefore(searchDate);

    assertEquals(1, foundList.size());

    searchDate = time.minusHours(6);
    foundList = notificationManager.findByCreatedAtBefore(searchDate);
    assertTrue(foundList.isEmpty());
}
 
@Test
public void testDeleteNotificationList() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime startDate = time.minusHours(1);
    OffsetDateTime endDate = time.plusHours(1);
    OffsetDateTime createdAt = time.minusHours(3);
    AlertNotificationModel entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    OffsetDateTime createdAtInRange = time.plusMinutes(1);
    AlertNotificationModel entityToFind1 = createNotificationModel(createdAtInRange);
    createdAtInRange = time.plusMinutes(5);
    AlertNotificationModel entityToFind2 = createNotificationModel(createdAtInRange);
    OffsetDateTime createdAtLater = time.plusHours(3);
    entity = createNotificationModel(createdAtLater);
    notificationManager.saveAllNotifications(List.of(entity));
    notificationManager.saveAllNotifications(List.of(entityToFind1));
    notificationManager.saveAllNotifications(List.of(entityToFind2));

    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
    assertEquals(4, notificationContentRepository.count());

    notificationManager.deleteNotificationList(foundList);

    assertEquals(2, notificationContentRepository.count());
}
 
源代码6 项目: dragonwell8_jdk   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码7 项目: dragonwell8_jdk   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码8 项目: openjdk-8-source   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码9 项目: TencentKona-8   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码10 项目: openjdk-8   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码11 项目: jdk8u-dev-jdk   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码12 项目: openjdk-jdk8u   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码13 项目: openjdk-jdk8u   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码14 项目: jdk8u-jdk   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码16 项目: jdk8u_jdk   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码17 项目: openjdk-jdk9   文件: TestOffsetDateTime.java
@Test
public void test_minusHours_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.minusHours(0);
    assertSame(test, base);
}
 
源代码18 项目: j2objc   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码19 项目: jdk8u_jdk   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}
 
源代码20 项目: openjdk-8-source   文件: TCKOffsetDateTime.java
@Test
public void test_minusHours() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.minusHours(13);
    assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
}