Search in sources :

Example 66 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class Commands method wereWithinPeriod.

/**
     * Creates a predicate for filtering commands created withing given timerange.
     */
public static Predicate<Command> wereWithinPeriod(final Timestamp from, final Timestamp to) {
    checkNotNull(from);
    checkNotNull(to);
    return new Predicate<Command>() {

        @Override
        public boolean apply(@Nullable Command request) {
            checkNotNull(request);
            final Timestamp timestamp = getTimestamp(request);
            return Timestamps2.isBetween(timestamp, from, to);
        }
    };
}
Also used : Timestamp(com.google.protobuf.Timestamp) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 67 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class WebSafeTimestampStringifierShould method convert_back_and_forth.

@Test
public void convert_back_and_forth() {
    final Timestamp timestamp = getCurrentTime();
    final Stringifier<Timestamp> stringifier = forTimestampWebSafe();
    final String str = stringifier.convert(timestamp);
    assertEquals(timestamp, stringifier.reverse().convert(str));
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 68 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class MessagesShould method pack_to_Any.

@Test
public void pack_to_Any() {
    final Timestamp timestamp = Time.getCurrentTime();
    assertEquals(timestamp, unpack(Messages.toAny(timestamp)));
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 69 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class Timestamps2Should method calculate_timestamp_of_moment_seconds_ago.

@Test
public void calculate_timestamp_of_moment_seconds_ago() {
    final Timestamp currentTime = getCurrentTime();
    final Timestamp expected = subtract(currentTime, TEN_SECONDS);
    final Timestamp actual = TimeTests.Past.secondsAgo(TEN_SECONDS.getSeconds());
    assertEquals(expected.getSeconds(), actual.getSeconds());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 70 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class Timestamps2Should method convert_timestamp_to_date_to_nearest_second.

@Test
public void convert_timestamp_to_date_to_nearest_second() {
    final Timestamp expectedTime = getCurrentTime();
    final Date actualDate = toDate(expectedTime);
    final long actualSeconds = actualDate.getTime() / MILLIS_PER_SECOND;
    assertEquals(expectedTime.getSeconds(), actualSeconds);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Date(java.util.Date) Timestamps2.toDate(io.spine.time.Timestamps2.toDate) Test(org.junit.Test)

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