Search in sources :

Example 96 with LocalTime

use of java.time.LocalTime in project jdk8u_jdk by JetBrains.

the class ZoneOffsetTransitionRule method readExternal.

/**
     * Reads the state from the stream.
     *
     * @param in  the input stream, not null
     * @return the created object, not null
     * @throws IOException if an error occurs
     */
static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException {
    int data = in.readInt();
    Month month = Month.of(data >>> 28);
    int dom = ((data & (63 << 22)) >>> 22) - 32;
    int dowByte = (data & (7 << 19)) >>> 19;
    DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte);
    int timeByte = (data & (31 << 14)) >>> 14;
    TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
    int stdByte = (data & (255 << 4)) >>> 4;
    int beforeByte = (data & (3 << 2)) >>> 2;
    int afterByte = (data & 3);
    LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0));
    ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
    ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
    ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
    return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after);
}
Also used : Month(java.time.Month) DayOfWeek(java.time.DayOfWeek) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset)

Example 97 with LocalTime

use of java.time.LocalTime in project jdk8u_jdk by JetBrains.

the class ChronoLocalDateTimeImpl method readExternal.

static ChronoLocalDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    ChronoLocalDate date = (ChronoLocalDate) in.readObject();
    LocalTime time = (LocalTime) in.readObject();
    return date.atTime(time);
}
Also used : LocalTime(java.time.LocalTime)

Example 98 with LocalTime

use of java.time.LocalTime in project jdk8u_jdk by JetBrains.

the class TimeTests method test10.

/*
     * Validate that a Time LocalTime value, made from a LocalTime are equal
     */
@Test
public void test10() {
    LocalTime lt = LocalTime.of(8, 30, 59);
    Time t = Time.valueOf(lt);
    System.out.println("lt=" + lt + ",t=" + t.toLocalTime());
    assertTrue(lt.equals(t.toLocalTime()), "Error LocalTime values are not equal");
}
Also used : LocalTime(java.time.LocalTime) Time(java.sql.Time) LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 99 with LocalTime

use of java.time.LocalTime in project jdk8u_jdk by JetBrains.

the class TimeTests method test11.

/*
     * Validate an NPE occurs when a null LocalDate is passed to valueOf
     */
@Test(expectedExceptions = NullPointerException.class)
public void test11() throws Exception {
    LocalTime ld = null;
    Time.valueOf(ld);
}
Also used : LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 100 with LocalTime

use of java.time.LocalTime in project jdk8u_jdk by JetBrains.

the class TCKOffsetDateTime method now_Clock_allSecsInDay_beforeEpoch.

@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
    LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
    for (int i = -1; i >= -(24 * 60 * 60); i--) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1969);
        assertEquals(test.getMonth(), Month.DECEMBER);
        assertEquals(test.getDayOfMonth(), 31);
        expected = expected.minusSeconds(1);
        assertEquals(test.toLocalTime(), expected);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
Also used : LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Aggregations

LocalTime (java.time.LocalTime)676 Test (org.junit.Test)262 Test (org.testng.annotations.Test)173 LocalDate (java.time.LocalDate)156 LocalDateTime (java.time.LocalDateTime)130 ZonedDateTime (java.time.ZonedDateTime)36 Date (java.util.Date)32 Instant (java.time.Instant)30 OffsetDateTime (java.time.OffsetDateTime)30 DateTimeFormatter (java.time.format.DateTimeFormatter)27 Test (org.junit.jupiter.api.Test)27 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)23 ZoneOffset (java.time.ZoneOffset)23 ZoneId (java.time.ZoneId)22 ArrayList (java.util.ArrayList)19 BigDecimal (java.math.BigDecimal)18 TemporalAccessor (java.time.temporal.TemporalAccessor)18 TemporalAmount (java.time.temporal.TemporalAmount)18 Time (java.sql.Time)17 Clock (java.time.Clock)17