Search in sources :

Example 11 with LocalTime

use of io.spine.time.LocalTime in project core-java by SpineEventEngine.

the class OffsetTimesShould method subtract_hours.

@Test
public void subtract_hours() {
    final int hoursDelta = random(1, 500);
    final Duration deltaDuration = Durations2.hours(hoursDelta);
    final Timestamp gmtPast = Timestamps.subtract(gmtNow, deltaDuration);
    final LocalTime expectedPast = LocalTimes.timeAt(gmtPast, zoneOffset);
    final LocalTime actualPast = subtractHours(now, hoursDelta).getTime();
    assertEquals(expectedPast, actualPast);
}
Also used : LocalTime(io.spine.time.LocalTime) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Example 12 with LocalTime

use of io.spine.time.LocalTime in project core-java by SpineEventEngine.

the class OffsetTimesShould method obtain_current.

@Test
public void obtain_current() {
    final OffsetTime now = OffsetTimes.now(zoneOffset);
    final Calendar cal = at(zoneOffset);
    final LocalTime time = now.getTime();
    assertEquals(getHours(cal), time.getHours());
    assertEquals(getMinutes(cal), time.getMinutes());
    assertEquals(getSeconds(cal), time.getSeconds());
    assertEquals(getZoneOffset(cal), now.getOffset().getAmountSeconds());
/* We cannot check milliseconds and nanos due to time gap between object creation */
}
Also used : LocalTime(io.spine.time.LocalTime) Calendar(java.util.Calendar) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Example 13 with LocalTime

use of io.spine.time.LocalTime in project core-java by SpineEventEngine.

the class OffsetTimesShould method add_seconds.

@Test
public void add_seconds() {
    final int secondsDelta = random(1, 300);
    final Duration deltaDuration = Durations2.seconds(secondsDelta);
    final Timestamp gmtFuture = Timestamps.add(gmtNow, deltaDuration);
    final LocalTime expectedFuture = LocalTimes.timeAt(gmtFuture, zoneOffset);
    final LocalTime actualFuture = addSeconds(now, secondsDelta).getTime();
    assertEquals(expectedFuture, actualFuture);
}
Also used : LocalTime(io.spine.time.LocalTime) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Example 14 with LocalTime

use of io.spine.time.LocalTime in project core-java by SpineEventEngine.

the class OffsetTimesShould method subtract_seconds.

@Test
public void subtract_seconds() {
    final int secondsDelta = random(1, 1024);
    final Duration deltaDuration = Durations2.seconds(secondsDelta);
    final Timestamp gmtPast = Timestamps.subtract(gmtNow, deltaDuration);
    final LocalTime expectedPast = LocalTimes.timeAt(gmtPast, zoneOffset);
    final LocalTime actualPast = subtractSeconds(now, secondsDelta).getTime();
    assertEquals(expectedPast, actualPast);
}
Also used : LocalTime(io.spine.time.LocalTime) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Example 15 with LocalTime

use of io.spine.time.LocalTime in project core-java by SpineEventEngine.

the class OffsetTimesShould method add_millis.

@Test
public void add_millis() {
    final int millisDelta = random(1, 100_000_000);
    final Duration deltaDuration = Durations.fromMillis(millisDelta);
    final Timestamp gmtFuture = Timestamps.add(gmtNow, deltaDuration);
    final LocalTime expectedFuture = LocalTimes.timeAt(gmtFuture, zoneOffset);
    final LocalTime actualFuture = addMillis(now, millisDelta).getTime();
    assertEquals(expectedFuture, actualFuture);
}
Also used : LocalTime(io.spine.time.LocalTime) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Aggregations

LocalTime (io.spine.time.LocalTime)19 Test (org.junit.Test)18 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)10 Duration (com.google.protobuf.Duration)8 Timestamp (com.google.protobuf.Timestamp)8 LocalTimeChange (io.spine.time.change.LocalTimeChange)1 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1