Java Code Examples for java.time.Instant#until()

The following examples show how to use java.time.Instant#until() . 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: TextClassifierImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@NonNull
private static List<LabeledIntent> createForDatetime(
        Context context, String type, @Nullable Instant referenceTime,
        Instant parsedTime) {
    if (referenceTime == null) {
        // If no reference time was given, use now.
        referenceTime = Instant.now();
    }
    List<LabeledIntent> actions = new ArrayList<>();
    actions.add(createCalendarViewIntent(context, parsedTime));
    final long millisUntilEvent = referenceTime.until(parsedTime, MILLIS);
    if (millisUntilEvent > MIN_EVENT_FUTURE_MILLIS) {
        actions.add(createCalendarCreateEventIntent(context, parsedTime, type));
    }
    return actions;
}
 
Example 2
Source File: TCKInstant.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 3
Source File: TCKInstant.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 4
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 5
Source File: TCKInstant.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 6
Source File: TCKInstant.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 7
Source File: TCKInstant.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("data_periodUntilUnit")
public void test_until_TemporalUnit_negated(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i2.until(i1, unit);
    assertEquals(amount, -expected);
}
 
Example 8
Source File: TCKInstant.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 9
Source File: TCKInstant.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit_negated(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i2.until(i1, unit);
    assertEquals(amount, -expected);
}
 
Example 10
Source File: TCKInstant.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 11
Source File: TCKInstant.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="periodUntilUnit")
public void test_until_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
    Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
    Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
    long amount = i1.until(i2, unit);
    assertEquals(amount, expected);
}
 
Example 12
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 13
Source File: TCKInstant.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 14
Source File: TCKInstant.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 15
Source File: TCKInstant.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 16
Source File: TCKInstant.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 17
Source File: TCKInstant.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 18
Source File: TCKInstant.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 19
Source File: ChestOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (respawns.isEmpty())
	{
		return null;
	}

	Instant now = Instant.now();
	for (Iterator<ChestRespawn> it = respawns.iterator(); it.hasNext(); )
	{
		ChestRespawn chestRespawn = it.next();

		float percent = 1.0f - (now.until(chestRespawn.getEndTime(), ChronoUnit.MILLIS) / (float) chestRespawn.getRespawnTime());
		if (percent > 1.0f)
		{
			it.remove();
			continue;
		}

		if (chestRespawn.getWorld() != client.getWorld())
		{
			continue;
		}

		WorldPoint worldPoint = chestRespawn.getWorldPoint();
		LocalPoint loc = LocalPoint.fromWorld(client, worldPoint);
		if (loc == null)
		{
			continue;
		}

		Point point = Perspective.localToCanvas(client, loc, client.getPlane(), 0);
		if (point == null)
		{
			continue;
		}

		if (respawnPieInverted)
		{
			percent = 1.0f - percent;
		}

		ProgressPieComponent ppc = new ProgressPieComponent();
		ppc.setDiameter(respawnPieDiameter);
		ppc.setBorderColor(pieBorderColor);
		ppc.setFill(pieFillColor);
		ppc.setPosition(point);
		ppc.setProgress(percent);
		ppc.render(graphics);
	}
	return null;
}
 
Example 20
Source File: Activity.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Calculates the elapsed time from {@link #getStartTime()} to now in terms of the specified unit.
 * <br>If {@link #getStartTime()} is {@code null} this will be negative.
 *
 * @param  unit
 *         The {@link java.time.temporal.TemporalUnit TemporalUnit} to return
 *
 * @throws IllegalArgumentException
 *         If the provided unit is {@code null}
 * @throws ArithmeticException
 *         If a numeric overflow occurs
 * @throws java.time.DateTimeException
 *         If the amount cannot be calculated
 * @throws java.time.temporal.UnsupportedTemporalTypeException
 *         If the provided unit is not supported
 *
 * @return Elapsed time in the provided {@link java.time.temporal.TemporalUnit TemporalUnit} or {@code -1} if unset
 *
 * @see    java.time.Instant#until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit) Instant.until(Temporal, TemporalUnit)
 * @see    java.time.temporal.TemporalUnit
 */
public long getElapsedTime(TemporalUnit unit)
{
    Checks.notNull(unit, "TemporalUnit");
    Instant start = getStartTime();
    return start != null ? start.until(Instant.now(), unit) : -1;
}