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

The following examples show how to use java.time.Instant#until() . 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
@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
@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
@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 Project: jdk8u60   File: TCKInstant.java    License: 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
@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 6
@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 Project: j2objc   File: TCKInstant.java    License: 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
@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
@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 10
@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
@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
@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 13
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 14
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 15
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 16
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 17
@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 Project: jdk8u60   File: TCKInstant.java    License: 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
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Instant start = Instant.ofEpochSecond(12, 3000);
    start.until(LocalTime.of(11, 30), SECONDS);
}
 
Example 20
Source Project: JDA   File: Activity.java    License: 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;
}