Java Code Examples for java.time.temporal.ChronoUnit#NANOS
The following examples show how to use
java.time.temporal.ChronoUnit#NANOS .
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: DateMatchers.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private static ChronoUnit convertUnit(final TimeUnit unit) { switch (unit) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case MINUTES: return ChronoUnit.MINUTES; case NANOSECONDS: return ChronoUnit.NANOS; case SECONDS: return ChronoUnit.SECONDS; default: throw new IllegalArgumentException("Unknown TimeUnit '" + unit + "'"); } }
Example 2
Source File: Timeouts.java From tascalate-concurrent with Apache License 2.0 | 6 votes |
private static ChronoUnit toChronoUnit(TimeUnit unit) { Objects.requireNonNull(unit, "unit"); switch (unit) { case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case SECONDS: return ChronoUnit.SECONDS; case MINUTES: return ChronoUnit.MINUTES; case HOURS: return ChronoUnit.HOURS; case DAYS: return ChronoUnit.DAYS; default: throw new IllegalArgumentException("Unknown TimeUnit constant"); } }
Example 3
Source File: TCKOffsetDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.chronology(), IsoChronology.INSTANCE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zoneId(), null}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zone(), OFFSET_PONE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.offset(), OFFSET_PONE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localDate(), LocalDate.of(2008, 6, 30)}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)}, }; }
Example 4
Source File: TCKLocalTime.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_12_30_40_987654321, TemporalQueries.chronology(), null}, {TEST_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_12_30_40_987654321, TemporalQueries.localDate(), null}, {TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321}, }; }
Example 5
Source File: TCKLocalDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.chronology(), IsoChronology.INSTANCE}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localDate(), LocalDate.of(2007, 7, 15)}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localTime(), LocalTime.of(12, 30, 40, 987654321)}, }; }
Example 6
Source File: DependencyGraphConfigurationTest.java From kieker with Apache License 2.0 | 5 votes |
@Test public void testWithLargeInputLog() throws Exception { // NOPMD (nothing to assert) // from within Eclipse: // . = <absolute path>/kieker/kieker-analysis/build-eclipse/kieker/analysisteetime/ // / = <absolute path>/kieker/kieker-analysis/build-eclipse/ final URL projectDir = ExampleConfigurationTest.class.getResource("/."); final File importDirectory = new File(projectDir.getFile(), "kieker-20170805-132418-9229368724068-UTC--KIEKER"); final File exportDirectory = new File(projectDir.getFile()); final DependencyGraphConfiguration configuration = new DependencyGraphConfiguration(importDirectory, ChronoUnit.NANOS, exportDirectory); final Execution<DependencyGraphConfiguration> execution = new Execution<>(configuration); execution.executeBlocking(); }
Example 7
Source File: TCKLocalTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_12_30_40_987654321, TemporalQueries.chronology(), null}, {TEST_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_12_30_40_987654321, TemporalQueries.localDate(), null}, {TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321}, }; }
Example 8
Source File: TCKOffsetDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.chronology(), IsoChronology.INSTANCE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zoneId(), null}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zone(), OFFSET_PONE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.offset(), OFFSET_PONE}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localDate(), LocalDate.of(2008, 6, 30)}, {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)}, }; }
Example 9
Source File: TCKLocalTime.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_12_30_40_987654321, TemporalQueries.chronology(), null}, {TEST_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_12_30_40_987654321, TemporalQueries.localDate(), null}, {TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321}, }; }
Example 10
Source File: TCKLocalDateTime.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.chronology(), IsoChronology.INSTANCE}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localDate(), LocalDate.of(2007, 7, 15)}, {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localTime(), LocalTime.of(12, 30, 40, 987654321)}, }; }
Example 11
Source File: TCKLocalTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_12_30_40_987654321, TemporalQueries.chronology(), null}, {TEST_12_30_40_987654321, TemporalQueries.zoneId(), null}, {TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_12_30_40_987654321, TemporalQueries.zone(), null}, {TEST_12_30_40_987654321, TemporalQueries.offset(), null}, {TEST_12_30_40_987654321, TemporalQueries.localDate(), null}, {TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321}, }; }
Example 12
Source File: TCKOffsetTime.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_11_30_59_500_PONE, TemporalQueries.chronology(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.zoneId(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_11_30_59_500_PONE, TemporalQueries.zone(), OFFSET_PONE}, {TEST_11_30_59_500_PONE, TemporalQueries.offset(), OFFSET_PONE}, {TEST_11_30_59_500_PONE, TemporalQueries.localDate(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)}, }; }
Example 13
Source File: TCKOffsetTime.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {TEST_11_30_59_500_PONE, TemporalQueries.chronology(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.zoneId(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.precision(), ChronoUnit.NANOS}, {TEST_11_30_59_500_PONE, TemporalQueries.zone(), OFFSET_PONE}, {TEST_11_30_59_500_PONE, TemporalQueries.offset(), OFFSET_PONE}, {TEST_11_30_59_500_PONE, TemporalQueries.localDate(), null}, {TEST_11_30_59_500_PONE, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)}, }; }
Example 14
Source File: Duration.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Returns a copy of this {@code Duration} truncated to the specified unit. * <p> * Truncating the duration returns a copy of the original with conceptual fields * smaller than the specified unit set to zero. * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will * round down towards zero to the nearest minute, setting the seconds and * nanoseconds to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all * {@linkplain ChronoUnit#isTimeBased() time-based units on {@code ChronoUnit}} * and {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return a {@code Duration} based on this duration with the time truncated, not null * @throws DateTimeException if the unit is invalid for truncation * @throws UnsupportedTemporalTypeException if the unit is not supported * @since 9 */ public Duration truncatedTo(TemporalUnit unit) { Objects.requireNonNull(unit, "unit"); if (unit == ChronoUnit.SECONDS && (seconds >= 0 || nanos == 0)) { return new Duration(seconds, 0); } else if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos; long result = (nod / dur) * dur; return plusNanos(result - nod); }
Example 15
Source File: LocalTime.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns a copy of this {@code LocalTime} with the time truncated. * <p> * Truncation returns a copy of the original time with fields * smaller than the specified unit set to zero. * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit * will set the second-of-minute and nano-of-second field to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all supplied time units on {@link ChronoUnit} and * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return a {@code LocalTime} based on this time with the time truncated, not null * @throws DateTimeException if unable to truncate * @throws UnsupportedTemporalTypeException if the unit is not supported */ public LocalTime truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = toNanoOfDay(); return ofNanoOfDay((nod / dur) * dur); }
Example 16
Source File: LocalTime.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Returns a copy of this {@code LocalTime} with the time truncated. * <p> * Truncation returns a copy of the original time with fields * smaller than the specified unit set to zero. * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit * will set the second-of-minute and nano-of-second field to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all supplied time units on {@link ChronoUnit} and * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return a {@code LocalTime} based on this time with the time truncated, not null * @throws DateTimeException if unable to truncate * @throws UnsupportedTemporalTypeException if the unit is not supported */ public LocalTime truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = toNanoOfDay(); return ofNanoOfDay((nod / dur) * dur); }
Example 17
Source File: Instant.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Returns a copy of this {@code Instant} truncated to the specified unit. * <p> * Truncating the instant returns a copy of the original with fields * smaller than the specified unit set to zero. * The fields are calculated on the basis of using a UTC offset as seen * in {@code toString}. * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will * round down to the nearest minute, setting the seconds and nanoseconds to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all supplied time units on {@link ChronoUnit} and * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return an {@code Instant} based on this instant with the time truncated, not null * @throws DateTimeException if the unit is invalid for truncation * @throws UnsupportedTemporalTypeException if the unit is not supported */ public Instant truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos; long result = (nod / dur) * dur; return plusNanos(result - nod); }
Example 18
Source File: ConsistentKeyLockerTest.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
@Override public ChronoUnit getUnit() { return ChronoUnit.NANOS; }
Example 19
Source File: CustomExtension.java From smallrye-fault-tolerance with Apache License 2.0 | 4 votes |
@Override public ChronoUnit durationUnit() { return ChronoUnit.NANOS; }
Example 20
Source File: Instant.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns a copy of this {@code Instant} truncated to the specified unit. * <p> * Truncating the instant returns a copy of the original with fields * smaller than the specified unit set to zero. * The fields are calculated on the basis of using a UTC offset as seen * in {@code toString}. * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will * round down to the nearest minute, setting the seconds and nanoseconds to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all supplied time units on {@link ChronoUnit} and * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return an {@code Instant} based on this instant with the time truncated, not null * @throws DateTimeException if the unit is invalid for truncation * @throws UnsupportedTemporalTypeException if the unit is not supported */ public Instant truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos; long result = (nod / dur) * dur; return plusNanos(result - nod); }