Search in sources :

Example 1 with ZoneOffset

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

the class TimeChangesShould method create_OffsetTimeChange_instance.

@Test
public void create_OffsetTimeChange_instance() {
    final ZoneOffset inKiev = ZoneOffsets.ofHours(3);
    final ZoneOffset inLuxembourg = ZoneOffsets.ofHours(1);
    final OffsetTime previousTime = OffsetTimes.now(inKiev);
    final OffsetTime newTime = OffsetTimes.now(inLuxembourg);
    final OffsetTimeChange result = TimeChanges.of(previousTime, newTime);
    assertEquals(previousTime, result.getPreviousValue());
    assertEquals(newTime, result.getNewValue());
}
Also used : OffsetTime(io.spine.time.OffsetTime) ZoneOffset(io.spine.time.ZoneOffset) Test(org.junit.Test)

Example 2 with ZoneOffset

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

the class ZoneOffsetsShould method get_current_zone_offset.

@Test
public void get_current_zone_offset() {
    final TimeZone timeZone = TimeZone.getDefault();
    final ZoneOffset zoneOffset = ZoneOffsets.getDefault();
    final Timestamp now = getCurrentTime();
    final long date = Timestamps.toMillis(now);
    final int offsetSeconds = timeZone.getOffset(date) / MILLIS_PER_SECOND;
    final String zoneId = timeZone.getID();
    assertEquals(zoneId, zoneOffset.getId());
    assertEquals(offsetSeconds, zoneOffset.getAmountSeconds());
}
Also used : TimeZone(java.util.TimeZone) Timestamp(com.google.protobuf.Timestamp) ZoneOffset(io.spine.time.ZoneOffset) Test(org.junit.Test)

Example 3 with ZoneOffset

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

the class ZoneOffsetsShould method adjust_zero_offset_without_zone.

@Test
public void adjust_zero_offset_without_zone() {
    Assert.assertEquals(ZoneOffsets.UTC, ZoneOffsets.adjustZero(ZoneOffsets.ofSeconds(0)));
    final ZoneOffset offset = ZoneOffsets.getDefault();
    Assert.assertEquals(offset, ZoneOffsets.adjustZero(offset));
    final ZoneOffset gmtOffset = ZoneConverter.getInstance().convert(TimeZone.getTimeZone("GMT"));
    checkNotNull(gmtOffset);
    Assert.assertEquals(gmtOffset, ZoneOffsets.adjustZero(gmtOffset));
}
Also used : ZoneOffset(io.spine.time.ZoneOffset) Test(org.junit.Test)

Example 4 with ZoneOffset

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

the class TimeChangesShould method do_not_accept_equal_OffsetDate_values.

@Test(expected = IllegalArgumentException.class)
public void do_not_accept_equal_OffsetDate_values() {
    final ZoneOffset inLuxembourg = ZoneOffsets.ofHours(1);
    final OffsetDate date = OffsetDates.now(inLuxembourg);
    TimeChanges.of(date, date);
}
Also used : OffsetDate(io.spine.time.OffsetDate) ZoneOffset(io.spine.time.ZoneOffset) Test(org.junit.Test)

Example 5 with ZoneOffset

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

the class TimeChangesShould method do_not_accept_null_OffsetTime_newValue.

@Test(expected = NullPointerException.class)
public void do_not_accept_null_OffsetTime_newValue() {
    final ZoneOffset inKiev = ZoneOffsets.ofHours(3);
    final OffsetTime now = OffsetTimes.now(inKiev);
    TimeChanges.of(now, null);
}
Also used : OffsetTime(io.spine.time.OffsetTime) ZoneOffset(io.spine.time.ZoneOffset) Test(org.junit.Test)

Aggregations

ZoneOffset (io.spine.time.ZoneOffset)18 Test (org.junit.Test)17 OffsetDate (io.spine.time.OffsetDate)4 OffsetDateTime (io.spine.time.OffsetDateTime)4 OffsetTime (io.spine.time.OffsetTime)4 Timestamp (com.google.protobuf.Timestamp)1 ActorContext (io.spine.base.ActorContext)1 CommandContext (io.spine.base.CommandContext)1 TenantId (io.spine.users.TenantId)1 UserId (io.spine.users.UserId)1 ParseException (java.text.ParseException)1 TimeZone (java.util.TimeZone)1