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

The following examples show how to use java.time.Instant#minusSeconds() . These examples are extracted from open source projects. 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 Project: digdag   File: CronScheduler.java    License: 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 Project: digdag   File: CronScheduler.java    License: 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
@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
@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
@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
@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
@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 Project: j2objc   File: TCKInstant.java    License: 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 9
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 10
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 11
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 12
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 13
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 14
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 15
Source Project: j2objc   File: TCKInstant.java    License: 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 16
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 17
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(-2, 0);
    i.minusSeconds(Long.MAX_VALUE);
}
 
Example 18
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}
 
Example 19
Source Project: hottub   File: TCKInstant.java    License: 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
@Test(expectedExceptions = {ArithmeticException.class})
public void minusSeconds_long_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(1, 0);
    i.minusSeconds(Long.MIN_VALUE + 1);
}