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

The following examples show how to use java.time.LocalDateTime#minusSeconds() . 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: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
Example 2
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
Example 3
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_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;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.minusSeconds(1);
        sec--;
        if (sec == -1) {
            min--;
            sec = 59;

            if (min == -1) {
                hour--;
                min = 59;

                if (hour == -1) {
                    hour = 23;
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
Example 4
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 5
Source File: TCKLocalDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_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;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.minusSeconds(1);
        sec--;
        if (sec == -1) {
            min--;
            sec = 59;

            if (min == -1) {
                hour--;
                min = 59;

                if (hour == -1) {
                    hour = 23;
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
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_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
Example 7
Source File: DeleteServiceStepTest.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private Date getOlderDateFromEvent(CloudEvent lastEvent) {
    ZoneId systemDefaultZone = ZoneId.systemDefault();
    Instant lastEventInstant = lastEvent.getTimestamp()
                                        .toInstant();
    LocalDateTime lastEventDateTime = LocalDateTime.ofInstant(lastEventInstant, systemDefaultZone);
    LocalDateTime secondBefore = lastEventDateTime.minusSeconds(1);
    Instant secondBeforeInstant = secondBefore.atZone(systemDefaultZone)
                                              .toInstant();
    return Date.from(secondBeforeInstant);
}
 
Example 8
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_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
Example 9
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_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;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.minusSeconds(1);
        sec--;
        if (sec == -1) {
            min--;
            sec = 59;

            if (min == -1) {
                hour--;
                min = 59;

                if (hour == -1) {
                    hour = 23;
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
Example 10
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 11
Source File: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 12
Source File: DateMinusSeconds.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void subtract_seconds_from_date_in_java8() {

	LocalDateTime newYearsDay = LocalDateTime.of(2013, Month.JANUARY, 1, 0,
			0);
	LocalDateTime newYearsEve = newYearsDay.minusSeconds(60);

	java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter
			.ofPattern("MM/dd/yyyy HH:mm:ss S");

	logger.info(newYearsDay.format(formatter));
	logger.info(newYearsEve.format(formatter));

	assertTrue(newYearsEve.isBefore(newYearsDay));
}
 
Example 13
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 14
Source File: DateProducer.java    From jfairy with Apache License 2.0 5 votes vote down vote up
public LocalDateTime randomDateInThePast(int maxYearsEarlier) {
	checkArgument(maxYearsEarlier >= 0, "%s has to be >= 0", maxYearsEarlier);
	LocalDateTime currentDate = timeProvider.getCurrentTime();
	LocalDateTime latestDateInThePast = currentDate.minusSeconds(SECONDS_BEFORE_TO_BE_IN_THE_PAST);
	LocalDateTime maxYearsEarlierDate = currentDate.minusYears(maxYearsEarlier);
	return randomDateBetweenTwoDates(maxYearsEarlierDate, latestDateInThePast);
}
 
Example 15
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
Example 16
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 17
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 18
Source File: OracleCDCSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private LocalDateTime adjustStartTime(LocalDateTime startTime) {
  return useLocalBuffering ? startTime : startTime.minusSeconds(configBean.txnWindow);
}
 
Example 19
Source File: DateTool.java    From axelor-open-suite with GNU Affero General Public License v3.0 2 votes vote down vote up
public static LocalDateTime minusSeconds(LocalDateTime datetime, long duration) {

    return datetime.minusSeconds(duration);
  }
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link java.time.LocalDateTime} that is {@code seconds} seconds before this date/time.
 *
 * @param self    a LocalDateTime
 * @param seconds the number of seconds to subtract
 * @return a LocalDateTime
 * @since 2.5.0
 */
public static LocalDateTime minus(final LocalDateTime self, long seconds) {
    return self.minusSeconds(seconds);
}