Java Code Examples for java.time.Instant#MAX
The following examples show how to use
java.time.Instant#MAX .
These examples are extracted from open source projects.
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 Project: openjdk-jdk8u File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 Project: FHIR File: SortingTest.java License: Apache License 2.0 | 6 votes |
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 3
Source Project: openjdk-8 File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 Project: openjdk-8-source File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 Project: jdk8u_jdk File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 Project: jdk8u-dev-jdk File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 Project: jdk8u-jdk File: TCKInstant.java License: GNU General Public License v2.0 | 6 votes |
@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 8
Source Project: vespa File: LogReader.java License: Apache License 2.0 | 5 votes |
/** 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 Project: swblocks-decisiontree File: ValueGroupTest.java License: Apache License 2.0 | 5 votes |
@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 Project: swblocks-decisiontree File: ValueGroupTest.java License: Apache License 2.0 | 5 votes |
@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 Project: openjdk-8-source File: FileTime.java License: GNU General Public License v2.0 | 4 votes |
/** * 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 Project: openAGV File: OrderHandler.java License: Apache License 2.0 | 4 votes |
private Instant deadline(Transport order) { return order.getDeadline() == null ? Instant.MAX : order.getDeadline(); }
Example 13
Source Project: jdk1.8-source-analysis File: FileTime.java License: Apache License 2.0 | 4 votes |
/** * 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 14
Source Project: jdk8u-dev-jdk File: FileTime.java License: GNU General Public License v2.0 | 4 votes |
/** * 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 15
Source Project: emodb File: CachingTableDAO.java License: Apache License 2.0 | 4 votes |
TableCacheEntry(Table table) { this.table = table; unknownTableReloadTime = Instant.MAX; }
Example 16
Source Project: j2objc File: TCKInstant.java License: Apache License 2.0 | 4 votes |
@Override protected List<TemporalAccessor> samples() { TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH}; return Arrays.asList(array); }
Example 17
Source Project: aws-sdk-java-v2 File: CachedSupplierTest.java License: Apache License 2.0 | 4 votes |
private Instant future() { return Instant.MAX; }
Example 18
Source Project: TencentKona-8 File: TCKInstant.java License: GNU General Public License v2.0 | 4 votes |
@Override protected List<TemporalAccessor> samples() { TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH}; return Arrays.asList(array); }
Example 19
Source Project: jdk8u-jdk File: FileTime.java License: GNU General Public License v2.0 | 4 votes |
/** * 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 20
Source Project: jdk8u60 File: FileTime.java License: GNU General Public License v2.0 | 4 votes |
/** * 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; }