Java Code Examples for java.time.Instant#MAX

The following examples show how to use java.time.Instant#MAX . 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: TCKInstant.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 2
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="with")
Object[][] data_with() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null},
            {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 3
Source File: TCKInstant.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 4
Source File: TCKInstant.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 5
Source File: TCKInstant.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 6
Source File: TCKInstant.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 7
Source File: SortingTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private void assertTrueNaturalOrderingReverseInstant(List<Instant> sortedList) {

        Iterator<Instant> primary = sortedList.iterator();

        if (DEBUG_SEARCH) {
            System.out.println(sortedList);
        }

        boolean done = false;
        Instant lastInstant = Instant.MAX;
        while (primary.hasNext()) {
            Instant thisInstant = primary.next();

            if (DEBUG_SEARCH) {
                System.out.println("Compare " + lastInstant + " " + lastInstant);
            }

            assertTrue(lastInstant.compareTo(thisInstant) == 0 || lastInstant.isAfter(thisInstant));
            lastInstant = thisInstant;
            // At least one
            done = true;
        }
        assertTrue(done);

    }
 
Example 8
Source File: LogReader.java    From vespa with Apache License 2.0 5 votes vote down vote up
/** Extracts a timestamp after all entries in the log file with the given path. */
Instant extractTimestamp(Path path) {
    String relativePath = logDirectory.relativize(path).toString();
    Matcher matcher = logArchivePathPattern.matcher(relativePath);
    if (matcher.matches()) {
        return ZonedDateTime.of(Integer.parseInt(matcher.group(1)),
                                Integer.parseInt(matcher.group(2)),
                                Integer.parseInt(matcher.group(3)),
                                Integer.parseInt(matcher.group(4)),
                                0,
                                0,
                                0,
                                ZoneId.of("UTC"))
                            .toInstant()
                            .plus(Duration.ofHours(1));
    }
    matcher = vespaLogPathPattern.matcher(relativePath);
    if (matcher.matches()) {
        if (matcher.group(1) == null)
            return Instant.MAX;

        return ZonedDateTime.of(Integer.parseInt(matcher.group(1)),
                                Integer.parseInt(matcher.group(2)),
                                Integer.parseInt(matcher.group(3)),
                                Integer.parseInt(matcher.group(4)),
                                Integer.parseInt(matcher.group(5)),
                                Integer.parseInt(matcher.group(6)),
                                0,
                                ZoneId.of("UTC"))
                            .toInstant()
                            .plus(Duration.ofSeconds(1));
    }
    throw new IllegalArgumentException("Unrecognized file pattern for file at '" + path + "'");
}
 
Example 9
Source File: ValueGroupTest.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
@Test
public void equalsCorrect() {
    final UUID uuid = new UUID(0, 1);
    final DateRange range = new DateRange(NOW, Instant.MAX);

    final ValueGroup group = new ValueGroup(uuid, "test-group", Arrays.asList("input1", "input2"), range);
    assertTrue(group.equals(group));

    assertFalse(group.equals(null));
    assertFalse(group.equals(Integer.parseInt("1")));

    ValueGroup other = new ValueGroup(new UUID(0, 1), "test-group",
            Arrays.asList("input1", "input2"), new DateRange(NOW, Instant.MAX));
    assertTrue(group.equals(other));

    other = new ValueGroup(new UUID(0, 2), "test-group",
            Arrays.asList("input1", "input2"), new DateRange(NOW, Instant.MAX));
    assertFalse(group.equals(other));

    other = new ValueGroup(new UUID(0, 1), "test-group1",
            Arrays.asList("input1", "input2"), new DateRange(NOW, Instant.MAX));
    assertFalse(group.equals(other));

    other = new ValueGroup(new UUID(0, 1), "test-group",
            Arrays.asList("input1"), new DateRange(NOW, Instant.MAX));
    assertFalse(group.equals(other));

    other = new ValueGroup(new UUID(0, 1), "test-group",
            Arrays.asList("input1", "input2"), ValueGroup.DEFAULT_DATE_RANGE);
    assertFalse(group.equals(other));
}
 
Example 10
Source File: ValueGroupTest.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructionFullConstructor() {
    final DateRange range = new DateRange(Instant.now(), Instant.MAX);

    final UUID id = new UUID(0, 50);
    this.bean = new ValueGroup(id, "test-group", Arrays.asList("input1", "input2"), range);

    this.injectedValues.put("id", id);
    this.injectedValues.put("name", "test-group");
    this.injectedValues.put("values", Arrays.asList("input1", "input2"));
    this.injectedValues.put("range", range);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, this.bean);
}
 
Example 11
Source File: FileTime.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Converts this {@code FileTime} object to an {@code Instant}.
 *
 * <p> The conversion creates an {@code Instant} that represents the
 * same point on the time-line as this {@code FileTime}.
 *
 * <p> {@code FileTime} can store points on the time-line further in the
 * future and further in the past than {@code Instant}. Conversion
 * from such further time points saturates to {@link Instant#MIN} if
 * earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
 * than {@code Instant.MAX}.
 *
 * @return  an instant representing the same point on the time-line as
 *          this {@code FileTime} object
 * @since 1.8
 */
public Instant toInstant() {
    if (instant == null) {
        long secs = 0L;
        int nanos = 0;
        switch (unit) {
            case DAYS:
                secs = scale(value, SECONDS_PER_DAY,
                             Long.MAX_VALUE/SECONDS_PER_DAY);
                break;
            case HOURS:
                secs = scale(value, SECONDS_PER_HOUR,
                             Long.MAX_VALUE/SECONDS_PER_HOUR);
                break;
            case MINUTES:
                secs = scale(value, SECONDS_PER_MINUTE,
                             Long.MAX_VALUE/SECONDS_PER_MINUTE);
                break;
            case SECONDS:
                secs = value;
                break;
            case MILLISECONDS:
                secs = Math.floorDiv(value, MILLIS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
                        * NANOS_PER_MILLI;
                break;
            case MICROSECONDS:
                secs = Math.floorDiv(value, MICROS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
                        * NANOS_PER_MICRO;
                break;
            case NANOSECONDS:
                secs = Math.floorDiv(value, NANOS_PER_SECOND);
                nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
                break;
            default : throw new AssertionError("Unit not handled");
        }
        if (secs <= MIN_SECOND)
            instant = Instant.MIN;
        else if (secs >= MAX_SECOND)
            instant = Instant.MAX;
        else
            instant = Instant.ofEpochSecond(secs, nanos);
    }
    return instant;
}
 
Example 12
Source File: FileTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts this {@code FileTime} object to an {@code Instant}.
 *
 * <p> The conversion creates an {@code Instant} that represents the
 * same point on the time-line as this {@code FileTime}.
 *
 * <p> {@code FileTime} can store points on the time-line further in the
 * future and further in the past than {@code Instant}. Conversion
 * from such further time points saturates to {@link Instant#MIN} if
 * earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
 * than {@code Instant.MAX}.
 *
 * @return  an instant representing the same point on the time-line as
 *          this {@code FileTime} object
 * @since 1.8
 */
public Instant toInstant() {
    if (instant == null) {
        long secs = 0L;
        int nanos = 0;
        switch (unit) {
            case DAYS:
                secs = scale(value, SECONDS_PER_DAY,
                             Long.MAX_VALUE/SECONDS_PER_DAY);
                break;
            case HOURS:
                secs = scale(value, SECONDS_PER_HOUR,
                             Long.MAX_VALUE/SECONDS_PER_HOUR);
                break;
            case MINUTES:
                secs = scale(value, SECONDS_PER_MINUTE,
                             Long.MAX_VALUE/SECONDS_PER_MINUTE);
                break;
            case SECONDS:
                secs = value;
                break;
            case MILLISECONDS:
                secs = Math.floorDiv(value, MILLIS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
                        * NANOS_PER_MILLI;
                break;
            case MICROSECONDS:
                secs = Math.floorDiv(value, MICROS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
                        * NANOS_PER_MICRO;
                break;
            case NANOSECONDS:
                secs = Math.floorDiv(value, NANOS_PER_SECOND);
                nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
                break;
            default : throw new AssertionError("Unit not handled");
        }
        if (secs <= MIN_SECOND)
            instant = Instant.MIN;
        else if (secs >= MAX_SECOND)
            instant = Instant.MAX;
        else
            instant = Instant.ofEpochSecond(secs, nanos);
    }
    return instant;
}
 
Example 13
Source File: CachingTableDAO.java    From emodb with Apache License 2.0 4 votes vote down vote up
TableCacheEntry(Table table) {
    this.table = table;
    unknownTableReloadTime = Instant.MAX;
}
 
Example 14
Source File: TCKInstant.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH};
    return Arrays.asList(array);
}
 
Example 15
Source File: CachedSupplierTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private Instant future() {
    return Instant.MAX;
}
 
Example 16
Source File: TCKInstant.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH};
    return Arrays.asList(array);
}
 
Example 17
Source File: FileTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts this {@code FileTime} object to an {@code Instant}.
 *
 * <p> The conversion creates an {@code Instant} that represents the
 * same point on the time-line as this {@code FileTime}.
 *
 * <p> {@code FileTime} can store points on the time-line further in the
 * future and further in the past than {@code Instant}. Conversion
 * from such further time points saturates to {@link Instant#MIN} if
 * earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
 * than {@code Instant.MAX}.
 *
 * @return  an instant representing the same point on the time-line as
 *          this {@code FileTime} object
 * @since 1.8
 */
public Instant toInstant() {
    if (instant == null) {
        long secs = 0L;
        int nanos = 0;
        switch (unit) {
            case DAYS:
                secs = scale(value, SECONDS_PER_DAY,
                             Long.MAX_VALUE/SECONDS_PER_DAY);
                break;
            case HOURS:
                secs = scale(value, SECONDS_PER_HOUR,
                             Long.MAX_VALUE/SECONDS_PER_HOUR);
                break;
            case MINUTES:
                secs = scale(value, SECONDS_PER_MINUTE,
                             Long.MAX_VALUE/SECONDS_PER_MINUTE);
                break;
            case SECONDS:
                secs = value;
                break;
            case MILLISECONDS:
                secs = Math.floorDiv(value, MILLIS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
                        * NANOS_PER_MILLI;
                break;
            case MICROSECONDS:
                secs = Math.floorDiv(value, MICROS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
                        * NANOS_PER_MICRO;
                break;
            case NANOSECONDS:
                secs = Math.floorDiv(value, NANOS_PER_SECOND);
                nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
                break;
            default : throw new AssertionError("Unit not handled");
        }
        if (secs <= MIN_SECOND)
            instant = Instant.MIN;
        else if (secs >= MAX_SECOND)
            instant = Instant.MAX;
        else
            instant = Instant.ofEpochSecond(secs, nanos);
    }
    return instant;
}
 
Example 18
Source File: FileTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts this {@code FileTime} object to an {@code Instant}.
 *
 * <p> The conversion creates an {@code Instant} that represents the
 * same point on the time-line as this {@code FileTime}.
 *
 * <p> {@code FileTime} can store points on the time-line further in the
 * future and further in the past than {@code Instant}. Conversion
 * from such further time points saturates to {@link Instant#MIN} if
 * earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
 * than {@code Instant.MAX}.
 *
 * @return  an instant representing the same point on the time-line as
 *          this {@code FileTime} object
 * @since 1.8
 */
public Instant toInstant() {
    if (instant == null) {
        long secs = 0L;
        int nanos = 0;
        switch (unit) {
            case DAYS:
                secs = scale(value, SECONDS_PER_DAY,
                             Long.MAX_VALUE/SECONDS_PER_DAY);
                break;
            case HOURS:
                secs = scale(value, SECONDS_PER_HOUR,
                             Long.MAX_VALUE/SECONDS_PER_HOUR);
                break;
            case MINUTES:
                secs = scale(value, SECONDS_PER_MINUTE,
                             Long.MAX_VALUE/SECONDS_PER_MINUTE);
                break;
            case SECONDS:
                secs = value;
                break;
            case MILLISECONDS:
                secs = Math.floorDiv(value, MILLIS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
                        * NANOS_PER_MILLI;
                break;
            case MICROSECONDS:
                secs = Math.floorDiv(value, MICROS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
                        * NANOS_PER_MICRO;
                break;
            case NANOSECONDS:
                secs = Math.floorDiv(value, NANOS_PER_SECOND);
                nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
                break;
            default : throw new AssertionError("Unit not handled");
        }
        if (secs <= MIN_SECOND)
            instant = Instant.MIN;
        else if (secs >= MAX_SECOND)
            instant = Instant.MAX;
        else
            instant = Instant.ofEpochSecond(secs, nanos);
    }
    return instant;
}
 
Example 19
Source File: OrderHandler.java    From openAGV with Apache License 2.0 4 votes vote down vote up
private Instant deadline(Transport order) {
  return order.getDeadline() == null ? Instant.MAX : order.getDeadline();
}
 
Example 20
Source File: FileTime.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts this {@code FileTime} object to an {@code Instant}.
 *
 * <p> The conversion creates an {@code Instant} that represents the
 * same point on the time-line as this {@code FileTime}.
 *
 * <p> {@code FileTime} can store points on the time-line further in the
 * future and further in the past than {@code Instant}. Conversion
 * from such further time points saturates to {@link Instant#MIN} if
 * earlier than {@code Instant.MIN} or {@link Instant#MAX} if later
 * than {@code Instant.MAX}.
 *
 * @return  an instant representing the same point on the time-line as
 *          this {@code FileTime} object
 * @since 1.8
 */
public Instant toInstant() {
    if (instant == null) {
        long secs = 0L;
        int nanos = 0;
        switch (unit) {
            case DAYS:
                secs = scale(value, SECONDS_PER_DAY,
                             Long.MAX_VALUE/SECONDS_PER_DAY);
                break;
            case HOURS:
                secs = scale(value, SECONDS_PER_HOUR,
                             Long.MAX_VALUE/SECONDS_PER_HOUR);
                break;
            case MINUTES:
                secs = scale(value, SECONDS_PER_MINUTE,
                             Long.MAX_VALUE/SECONDS_PER_MINUTE);
                break;
            case SECONDS:
                secs = value;
                break;
            case MILLISECONDS:
                secs = Math.floorDiv(value, MILLIS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MILLIS_PER_SECOND)
                        * NANOS_PER_MILLI;
                break;
            case MICROSECONDS:
                secs = Math.floorDiv(value, MICROS_PER_SECOND);
                nanos = (int)Math.floorMod(value, MICROS_PER_SECOND)
                        * NANOS_PER_MICRO;
                break;
            case NANOSECONDS:
                secs = Math.floorDiv(value, NANOS_PER_SECOND);
                nanos = (int)Math.floorMod(value, NANOS_PER_SECOND);
                break;
            default : throw new AssertionError("Unit not handled");
        }
        if (secs <= MIN_SECOND)
            instant = Instant.MIN;
        else if (secs >= MAX_SECOND)
            instant = Instant.MAX;
        else
            instant = Instant.ofEpochSecond(secs, nanos);
    }
    return instant;
}