Java Code Examples for java.time.LocalTime#toNanoOfDay()

The following examples show how to use java.time.LocalTime#toNanoOfDay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLocalTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 2
Source File: ExpressionTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalTimeValueLiteralExtraction() {
	final LocalTime localTime = LocalTime.of(12, 12, 12, 123456789);

	final long nanos = localTime.toNanoOfDay();

	final int millis = localTime.get(ChronoField.MILLI_OF_DAY);

	final Time sqlTime = Time.valueOf("12:12:12");

	assertEquals(
		localTime.withNano(0),
		new ValueLiteralExpression(sqlTime).getValueAs(LocalTime.class)
			.orElseThrow(AssertionError::new));

	assertEquals(
		localTime,
		new ValueLiteralExpression(nanos).getValueAs(LocalTime.class)
			.orElseThrow(AssertionError::new));

	assertEquals(
		localTime.minusNanos(456789),
		new ValueLiteralExpression(millis).getValueAs(LocalTime.class)
			.orElseThrow(AssertionError::new));
}
 
Example 3
Source File: TestLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 4
Source File: TestLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 5
Source File: TestLocalTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 6
Source File: TestLocalTime.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 7
Source File: TestLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 8
Source File: TestLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 9
Source File: TestLocalTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 10
Source File: TestLocalTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 11
Source File: TestLocalTime.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 12
Source File: TestLocalTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 13
Source File: TestLocalTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unused")
public void now() {
    // Warmup the TimeZone data so the following test does not include
    // one-time initialization
    LocalTime.now(Clock.systemDefaultZone());

    long diff = Integer.MAX_VALUE;
    for (int i = 0; i < 2; i++) {
        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
        LocalTime test = LocalTime.now();
        diff = test.toNanoOfDay() - expected.toNanoOfDay();
        // Normalize for wrap-around midnight
        diff = Math.floorMod(NANOS_PER_DAY + diff, NANOS_PER_DAY);
        if (diff < 100000000) {
            break;
        }
        // A second iteration may be needed if the clock changed
        // due to a DST change between the two calls to now.
    }
    assertTrue(diff < 100000000,   // less than 0.1 sec
            "LocalTime.now  vs LocalTime.now(Clock.systemDefaultZone()) not close");
}
 
Example 14
Source File: CassandraRowMapperFnTest.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeColumn() {
  LocalTime now = LocalTime.now(ZoneId.systemDefault());

  Long value = now.toNanoOfDay();
  primeWithType(value, TIME);
  ResultSet resultSet = getResultSet();

  Schema schema = Schema.builder().addNullableField("col", FieldType.INT64).build();
  Row expected = Row.withSchema(schema).addValue(value).build();

  assertEquals(expected, cassandraRowMapper.map(resultSet).next());
}
 
Example 15
Source File: KdbUtility.java    From FX-AlgorithmTrading with MIT License 5 votes vote down vote up
/**
 * Convert from Java:LocalTime to kdb:timespan.
 * @param localTime
 * @return
 */
public static QTimespan kdbValueTimespan(LocalTime localTime) {
    if (localTime == null) {
        try {
            return (QTimespan) QType.getQNull(QType.TIMESPAN);
        } catch (QException e) {
            logger.error("", e);
        }
    }
    return new QTimespan(localTime.toNanoOfDay());
}
 
Example 16
Source File: LongCoding.java    From morpheus-core with Apache License 2.0 4 votes vote down vote up
@Override
public final long getCode(LocalTime value) {
    return value == null ? Long.MIN_VALUE : value.toNanoOfDay();
}
 
Example 17
Source File: LocalTimeConverter.java    From PgBulkInsert with MIT License 4 votes vote down vote up
@Override
public Long convert(final LocalTime time) {
    return time.toNanoOfDay() / 1000L;
}
 
Example 18
Source File: DateTimeUtil.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public static long microsFromTime(LocalTime time) {
  return time.toNanoOfDay() / 1000;
}
 
Example 19
Source File: Time.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public Long toBaseType(LocalTime input) {
  return input == null ? null : input.toNanoOfDay();
}
 
Example 20
Source File: IntegerColumnLocalTimeMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public Integer toNonNullValue(LocalTime value) {
    final Integer integer = (int) (value.toNanoOfDay() / 1000000);
    return integer;
}