Java Code Examples for java.time.Instant.MAX

The following are Jave code examples for showing how to use MAX of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 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
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 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 3
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 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
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 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 5
Project: swblocks-decisiontree   File: DatedTreeNodeTest.java   Source Code and License Vote up 6 votes
@Test
public void addNodeUpdatesDateRangeEnd() {
    final TreeNode root = createDatedTreeNode("Root", Instant.MIN, Instant.MAX);

    final Instant start = NOW.minus(Period.ofWeeks(5));
    final Instant end = NOW.plus(Period.ofWeeks(5));

    final TreeNode node = createDatedTreeNode("Test1", start, end);
    root.addNode(node);

    final TreeNode other = createDatedTreeNode("Test1", start, Instant.MAX);
    root.addNode(other);
    assertEquals(node, root.getExactNode(node).get());

    final Range<Instant> range = new Range<>(start, Instant.MAX);
    assertEquals(range, node.getDateRange());
}
 
Example 6
Project: swblocks-jbl   File: DateRangeTest.java   Source Code and License Vote up 5 votes
@Test
public void testHashcode() {
    final Instant start = Instant.MIN;
    final Instant end = Instant.MAX;

    final DateRange dateRange = new DateRange(start, end);
    assertEquals(-962094838, dateRange.hashCode());
}
 
Example 7
Project: swblocks-jbl   File: RangeTest.java   Source Code and License Vote up 5 votes
@Test
public void testHashcode() {
    final Instant start = Instant.MIN;
    final Instant end = Instant.MAX;

    final Range<Instant> instantRange = new Range<>(start, end);
    assertEquals(-962094838, instantRange.hashCode());
}
 
Example 8
Project: swblocks-decisiontree   File: DatedTreeNodeTest.java   Source Code and License Vote up 5 votes
@Test
public void dateRange() {
    final Instant start = NOW.minus(Period.ofWeeks(5));
    final Instant end = NOW.plus(Period.ofWeeks(5));

    final TreeNode node = createDatedTreeNode("Test1", start, end);

    Range<Instant> range = new Range<>(start, end);
    assertEquals(range, node.getDateRange());

    range = new Range<Instant>(Instant.MIN, Instant.MAX);
    node.setDateRange(range);
    assertEquals(range, node.getDateRange());
}
 
Example 9
Project: swblocks-decisiontree   File: ValueGroupTest.java   Source Code and License Vote up 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 10
Project: swblocks-decisiontree   File: ValueGroupTest.java   Source Code and License Vote up 5 votes
@Test
public void updatesValues() {
    final DateRange range = new DateRange(Instant.now(), Instant.MAX);
    final ValueGroup group =
            new ValueGroup(UUID.randomUUID(), "test-group", Arrays.asList("input1", "input2"), range);
    assertThat(group.getValues(), contains("input1", "input2"));

    final List<String> values = Collections.singletonList("input3");
    group.updateValues(values);
    assertThat(group.getValues(), contains("input3"));

    group.updateValues(new ArrayList<>(1));
    assertThat(group.getValues(), contains("input3"));

}
 
Example 11
Project: swblocks-decisiontree   File: ValueGroupTest.java   Source Code and License Vote up 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 12
Project: swblocks-decisiontree   File: ValueGroupTest.java   Source Code and License Vote up 5 votes
@Test
public void hashCodeCorrect() {
    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);

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

    assertTrue(group.hashCode() == other.hashCode());
}
 
Example 13
Project: swblocks-decisiontree   File: ValueGroupTest.java   Source Code and License Vote up 5 votes
@Test
public void toStringCorrect() {
    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);

    Assert.assertEquals(GroupDriver.VG_PREFIX + new UUID(0, 1), group.toString());
}
 
Example 14
Project: OpenJSharp   File: FileTime.java   Source Code and License Vote up 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
Project: jdk8u-jdk   File: FileTime.java   Source Code and License Vote up 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 16
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH};
    return Arrays.asList(array);
}
 
Example 17
Project: aws-sdk-java-v2   File: CachedSupplierTest.java   Source Code and License Vote up 4 votes
private Instant future() {
    return Instant.MAX;
}
 
Example 18
Project: openjdk-jdk10   File: FileTime.java   Source Code and License Vote up 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 19
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12345_123456789, Instant.MIN, Instant.MAX, Instant.EPOCH};
    return Arrays.asList(array);
}