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

The following examples show how to use java.time.Instant#plusMillis() . 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: hottub   File: TCKInstant.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="PlusMillis")
public void plusMillis_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 2
@Test
public void plusMillis_long_max() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 998999999);
    t = t.plusMillis(1);
    assertEquals(t.getEpochSecond(), MAX_SECOND);
    assertEquals(t.getNano(), 999999999);
}
 
Example 3
@Test
public void plusMillis_long_min() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 1000000);
    t = t.plusMillis(-1);
    assertEquals(t.getEpochSecond(), MIN_SECOND);
    assertEquals(t.getNano(), 0);
}
 
Example 4
@Test(dataProvider="PlusMillis")
public void plusMillis_long_oneMore(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds + 1, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds + 1);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 5
@Test(dataProvider="PlusMillis")
public void plusMillis_long_minusOneLess(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds - 1, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds - 1);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 6
@Test
public void plusMillis_long_min() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 1000000);
    t = t.plusMillis(-1);
    assertEquals(t.getEpochSecond(), MIN_SECOND);
    assertEquals(t.getNano(), 0);
}
 
Example 7
Source Project: j2objc   File: TCKInstant.java    License: Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("provider_plusMillis_long")
public void plusMillis_long_minusOneLess(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds - 1, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds - 1);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 8
@Test
public void plusMillis_long_max() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 998999999);
    t = t.plusMillis(1);
    assertEquals(t.getEpochSecond(), MAX_SECOND);
    assertEquals(t.getNano(), 999999999);
}
 
Example 9
@Test(dataProvider="PlusMillis")
public void plusMillis_long_minusOneLess(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds - 1, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds - 1);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 10
Source Project: jdk8u60   File: TCKInstant.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void plusMillis_long_min() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 1000000);
    t = t.plusMillis(-1);
    assertEquals(t.getEpochSecond(), MIN_SECOND);
    assertEquals(t.getNano(), 0);
}
 
Example 11
Source Project: hottub   File: TCKInstant.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 999000000);
    t.plusMillis(1);
}
 
Example 12
public List filterEvents(List events, String[] customFieldNames, String tzid) throws ImportException
{
	ZoneId dstZoneId = ZoneId.of(getTimeService().getLocalTimeZone().getID());		
	ZoneId srcZoneId;
	if (tzid != null) {
		srcZoneId = ZoneId.of(tzid);
	} else {
		srcZoneId = dstZoneId;
	}
	setColumnDelimiter(",");

	Iterator it = events.iterator();
	
	//
	// Convert the date/time fields as they appear in the Outlook import to
	// be a synthesized start/end timerange.
	//
	while ( it.hasNext() )
	{
		Map eventProperties = (Map)it.next();

		Date startTime = (Date) eventProperties.get(defaultHeaderMap.get(GenericCalendarImporter.START_TIME_DEFAULT_COLUMN_HEADER));
		Date startDate = (Date) eventProperties.get(defaultHeaderMap.get(GenericCalendarImporter.DATE_DEFAULT_COLUMN_HEADER));
		Date endTime = (Date) eventProperties.get(defaultHeaderMap.get(GenericCalendarImporter.END_TIME_DEFAULT_COLUMN_HEADER));
		Date endDate = (Date) eventProperties.get(defaultHeaderMap.get(GenericCalendarImporter.ENDS_DEFAULT_COLUMN_HEADER));
		
		if (startTime == null ) {
			throw new ImportException(rb.getString("err_no_stime"));
		}
		if (endTime == null ) {
			throw new ImportException(rb.getString("err_no_etime"));
		}
		
		// Raw date + raw time
		Instant startInstant = startTime.toInstant();
		Instant endInstant = endTime.toInstant();
		
		if (startDate != null) {
			startInstant = startInstant.plusMillis(startDate.getTime());
		}
		if (endDate != null) {
			endInstant = endInstant.plusMillis(endDate.getTime());
		}
		
		// Duration of event
		long duration = endInstant.toEpochMilli() - startInstant.toEpochMilli();
		
		// Raw + calendar/owner TZ's offset
		ZonedDateTime srcZonedDateTime = startInstant.atZone(srcZoneId);
		long millis = startInstant.plusMillis(srcZonedDateTime.getOffset().getTotalSeconds() * 1000).toEpochMilli();

		// Time Service will ajust to current user's TZ
		eventProperties.put(GenericCalendarImporter.ACTUAL_TIMERANGE,
			getTimeService().newTimeRange(millis, duration));
		
	}
	
	return events;
}
 
Example 13
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 999000000);
    t.plusMillis(1);
}
 
Example 14
Source Project: hottub   File: TCKInstant.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooSmall() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 0);
    t.plusMillis(-1);
}
 
Example 15
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 999000000);
    t.plusMillis(1);
}
 
Example 16
/**
 * Test case
 * Time firstTick) attempt to load the place returns not found
 * Time cachedTick) a second, very quick, request gets the same negative cache entry
 * Time expiredTick) a bit later a new request is made, the cache entry is expired and re-loaded, this time with data
 * Time recachedTick) a bit later another request is made, this time returning the same entry 
 */
@Test
public void testEnvironmentNotFoundThenFound() {
   Instant firstTick = Instant.now();
   Instant cachedTick = firstTick.plusMillis(100);
   Instant expiredTick = cachedTick.plus(10, ChronoUnit.MINUTES);
   Instant recachedTick = expiredTick.plusMillis(100);
   
   Optional<PlaceEnvironmentExecutor> executorRef;
   
   {
      expectPlaceNotFound(placeId);
      replay();
      
      setTime(firstTick);
      executorRef = registry.getExecutor(placeId);
      assertFalse(executorRef.isPresent());
      assertTrue(registry.isCached(placeId));
      
      setTime(cachedTick);
      executorRef = registry.getExecutor(placeId);
      assertFalse(executorRef.isPresent());
      assertTrue(registry.isCached(placeId));
      
      verify();
   }
   
   reset();
   
   {
      expectLoadPlace(placeId);
      replay();
   
      setTime(expiredTick);
      executorRef = registry.getExecutor(placeId);
      assertTrue(executorRef.isPresent());
      assertTrue(registry.isCached(placeId));
      
      // additional access should return the same instance
      setTime(recachedTick);
      assertEquals(executorRef, registry.getExecutor(placeId));
      
      verify();
   }
}
 
Example 17
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooSmall() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 0);
    t.plusMillis(-1);
}
 
Example 18
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 999000000);
    t.plusMillis(1);
}
 
Example 19
@Test(expectedExceptions=DateTimeException.class)
public void plusMillis_long_overflowTooSmall() {
    Instant t = Instant.ofEpochSecond(MIN_SECOND, 0);
    t.plusMillis(-1);
}
 
Example 20
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 plusMillis_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(MAX_SECOND, 999000000);
    t.plusMillis(1);
}