use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class GivenCommandContext method withRandomActor.
/**
* Creates a new {@link CommandContext} instance with a randomly
* generated {@linkplain UserId actor} and current timestamp as a creation date.
*
* @return a new {@code CommandContext} instance
*/
public static CommandContext withRandomActor() {
final UserId userId = GivenUserId.newUuid();
final Timestamp now = getCurrentTime();
return withActorAndTime(userId, now);
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class CommandTestShould method create_different_command_with_timestamp.
@Test
public void create_different_command_with_timestamp() {
final Message anotherCommandMsg = Time.getCurrentTime();
final Timestamp timestamp = TimeTests.Past.minutesAgo(30);
final Command anotherCommand = commandTest.createDifferentCommand(anotherCommandMsg, timestamp);
assertEquals(anotherCommandMsg, Commands.getMessage(anotherCommand));
assertEquals(timestamp, anotherCommand.getContext().getActorContext().getTimestamp());
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class CommandTestShould method create_command_with_custom_Timestamp.
@Test
public void create_command_with_custom_Timestamp() {
final StringValue commandMessage = newUuidValue();
final Timestamp timestamp = TimeTests.Past.minutesAgo(5);
final Command command = commandTest.createCommand(commandMessage, timestamp);
assertEquals(timestamp, command.getContext().getActorContext().getTimestamp());
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class Intervals method toDuration.
/**
* Returns a duration of the interval.
*
* @param interval the interval to calculate its duration
* @return the duration between the start and the end of the interval
*/
public static Duration toDuration(Interval interval) {
final Timestamp start = interval.getStart();
final Timestamp end = interval.getEnd();
if (start.equals(end)) {
return Durations2.ZERO;
}
final long secondsBetween = end.getSeconds() - start.getSeconds();
final int nanosBetween = end.getNanos() - start.getNanos();
final Duration.Builder duration = Duration.newBuilder().setSeconds(abs(secondsBetween)).setNanos(abs(nanosBetween));
return duration.build();
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class LocalTimes method now.
/**
* Obtains current local time.
*/
public static LocalTime now() {
final Timestamp time = Time.getCurrentTime();
final ZoneOffset zoneOffset = ZoneOffsets.getDefault();
return timeAt(time, zoneOffset);
}
Aggregations