Search in sources :

Example 51 with Timestamp

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);
}
Also used : UserId(io.spine.core.UserId) Timestamp(com.google.protobuf.Timestamp)

Example 52 with Timestamp

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());
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 53 with Timestamp

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());
}
Also used : Command(io.spine.core.Command) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 54 with Timestamp

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();
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp)

Example 55 with Timestamp

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);
}
Also used : Timestamp(com.google.protobuf.Timestamp)

Aggregations

Timestamp (com.google.protobuf.Timestamp)120 Test (org.junit.Test)84 Duration (com.google.protobuf.Duration)24 Interval (io.spine.time.Interval)16 Command (io.spine.core.Command)9 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Nullable (javax.annotation.Nullable)7 StringValue (com.google.protobuf.StringValue)6 Event (io.spine.core.Event)6 Message (com.google.protobuf.Message)5 Predicate (com.google.common.base.Predicate)4 TimeTests (io.spine.test.TimeTests)4 CommandContext (io.spine.core.CommandContext)3 EventContext (io.spine.core.EventContext)3 Version (io.spine.core.Version)3 Any (com.google.protobuf.Any)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2