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

The following examples show how to use java.time.Instant#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: CronScheduler.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Override
public ScheduleTime getFirstScheduleTime(Instant currentTime)
{
    Instant startTime = currentTime;  // TODO make this from config

    // truncate to seconds
    Instant truncated = Instant.ofEpochSecond(currentTime.getEpochSecond());
    if (truncated.equals(currentTime)) {
        // in this particular case, minus 1 second to include this currentTime
        // because Predictor doesn't include this time at "next"MatchingTime() method
        truncated = truncated.minusSeconds(1);
    }
    Instant lastTime = truncated.minusSeconds(delaySeconds);

    return nextScheduleTime(lastTime);
}
 
Example 2
Source File: CronScheduler.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Override
public ScheduleTime lastScheduleTime(Instant currentScheduleTime)
{
    // estimate interval (doesn't have to be exact value)
    Instant next = next(currentScheduleTime);
    Instant nextNext = next(next);
    long estimatedInterval = nextNext.getEpochSecond() - next.getEpochSecond();

    // get an aligned time that is before currentScheduleTime
    Instant before = currentScheduleTime.minusSeconds(estimatedInterval);
    do {
        before = before.minusSeconds(estimatedInterval);
    } while(!before.isBefore(currentScheduleTime));

    // before is before currentScheduleTime but not sure how many times before. calculate it.
    Instant nextOfBefore = next(before);
    while (nextOfBefore.isBefore(currentScheduleTime)) {
        before = nextOfBefore;
        nextOfBefore = next(before);
    }

    // nextOfBefore is same with currentScheduleTime or after currentScheduleTime. nextOfBefore is next of before. done.
    return ScheduleTime.of(before, before.plusSeconds(delaySeconds));
}
 
Example 3
Source File: TCKInstant.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 4
Source File: TCKInstant.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 5
Source File: TCKInstant.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 6
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 7
Source File: TCKInstant.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MinusSeconds")
public void minusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant i = Instant.ofEpochSecond(seconds, nanos);
    i = i.minusSeconds(amount);
    assertEquals(i.getEpochSecond(), expectedSeconds);
    assertEquals(i.getNano(), expectedNanoOfSecond);
}
 
Example 8
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 9
Source File: TCKInstant.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=ArithmeticException.class)
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 10
Source File: TCKInstant.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 11
Source File: TCKInstant.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 12
Source File: TCKInstant.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 13
Source File: TCKInstant.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 14
Source File: TCKInstant.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=ArithmeticException.class)
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 15
Source File: TCKInstant.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 16
Source File: TCKInstant.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 17
Source File: TCKInstant.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 18
Source File: TCKInstant.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 19
Source File: TCKInstant.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 20
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}