use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class IntervalsShould method calculate_duration_of_interval.
@Test
public void calculate_duration_of_interval() {
final Timestamp start = newTimestamp(5, 6);
final Timestamp end = newTimestamp(10, 10);
final Duration expectedDuration = Duration.newBuilder().setSeconds(end.getSeconds() - start.getSeconds()).setNanos(end.getNanos() - start.getNanos()).build();
final Interval interval = Intervals.between(start, end);
final Duration actualDuration = Intervals.toDuration(interval);
assertEquals(expectedDuration, actualDuration);
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class Commands method isScheduled.
/**
* Checks if the command is scheduled to be delivered later.
*
* @param command a command to check
* @return {@code true} if the command context has a scheduling option set,
* {@code false} otherwise
*/
public static boolean isScheduled(Command command) {
checkNotNull(command);
final Schedule schedule = command.getContext().getSchedule();
final Duration delay = schedule.getDelay();
if (isNotDefault(delay)) {
checkArgument(delay.getSeconds() > 0, "Command delay seconds must be a positive value.");
return true;
}
return false;
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class OffsetTimesShould method subtract_minutes.
@Test
public void subtract_minutes() {
final int minutesDelta = random(1, 1024);
final Duration deltaDuration = Durations2.minutes(minutesDelta);
final Timestamp gmtPast = Timestamps.subtract(gmtNow, deltaDuration);
final LocalTime expectedPast = LocalTimes.timeAt(gmtPast, zoneOffset);
final LocalTime actualPast = subtractMinutes(now, minutesDelta).getTime();
assertEquals(expectedPast, actualPast);
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class OffsetTimesShould method add_hours.
/*
* Math with time
*/
@Test
public void add_hours() {
final int hoursDelta = random(1, 100);
final Duration deltaDuration = Durations2.hours(hoursDelta);
final Timestamp gmtFuture = Timestamps.add(gmtNow, deltaDuration);
final LocalTime expectedFuture = LocalTimes.timeAt(gmtFuture, zoneOffset);
final LocalTime actualFuture = addHours(now, hoursDelta).getTime();
assertEquals(expectedFuture, actualFuture);
}
use of com.google.protobuf.Duration in project core-java by SpineEventEngine.
the class ZoneOffsetsShould method create_instance_by_hours_offset.
@Test
public void create_instance_by_hours_offset() {
final Duration twoHours = hours(2);
Assert.assertEquals(twoHours.getSeconds(), ZoneOffsets.ofHours(2).getAmountSeconds());
}
Aggregations